fix 修复文件上传图片预览问题

2.X
AprilWind 8 months ago
parent d7ee4f589c
commit d9d9765a4a

@ -165,10 +165,11 @@ public class OssClient {
* @param filePath
* @param key Amazon S3
* @param md5Digest MD5
* @param contentType
* @return UploadResult
* @throws OssException
*/
public UploadResult upload(Path filePath, String key, String md5Digest) {
public UploadResult upload(Path filePath, String key, String md5Digest, String contentType) {
try {
// 构建上传请求对象
FileUpload fileUpload = transferManager.uploadFile(
@ -176,6 +177,7 @@ public class OssClient {
y -> y.bucket(properties.getBucketName())
.key(key)
.contentMD5(StringUtils.isNotEmpty(md5Digest) ? md5Digest : null)
.contentType(contentType)
.build())
.addTransferListener(LoggingTransferListener.create())
.source(filePath).build());
@ -201,10 +203,11 @@ public class OssClient {
* @param inputStream
* @param key Amazon S3
* @param length
* @param contentType
* @return UploadResult
* @throws OssException
*/
public UploadResult upload(InputStream inputStream, String key, Long length) {
public UploadResult upload(InputStream inputStream, String key, Long length, String contentType) {
// 如果输入流不是 ByteArrayInputStream则将其读取为字节数组再创建 ByteArrayInputStream
if (!(inputStream instanceof ByteArrayInputStream)) {
inputStream = new ByteArrayInputStream(IoUtil.readBytes(inputStream));
@ -219,6 +222,7 @@ public class OssClient {
.putObjectRequest(
y -> y.bucket(properties.getBucketName())
.key(key)
.contentType(contentType)
.build())
.build());
@ -335,7 +339,7 @@ public class OssClient {
* @throws OssException
*/
public UploadResult uploadSuffix(byte[] data, String suffix) {
return upload(new ByteArrayInputStream(data), getPath(properties.getPrefix(), suffix), Long.valueOf(data.length));
return upload(new ByteArrayInputStream(data), getPath(properties.getPrefix(), suffix), Long.valueOf(data.length), FileUtils.getMimeType(suffix));
}
/**
@ -348,7 +352,7 @@ public class OssClient {
* @throws OssException
*/
public UploadResult uploadSuffix(InputStream inputStream, String suffix, Long length) {
return upload(inputStream, getPath(properties.getPrefix(), suffix), length);
return upload(inputStream, getPath(properties.getPrefix(), suffix), length, FileUtils.getMimeType(suffix));
}
/**
@ -360,7 +364,7 @@ public class OssClient {
* @throws OssException
*/
public UploadResult uploadSuffix(File file, String suffix) {
return upload(file.toPath(), getPath(properties.getPrefix(), suffix), null);
return upload(file.toPath(), getPath(properties.getPrefix(), suffix), null, FileUtils.getMimeType(suffix));
}
/**

Loading…
Cancel
Save