update OSS接口增加通用contentType
This commit is contained in:
parent
eea8f33cf9
commit
a4c019ace2
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>ruoyi-vue-plus</artifactId>
|
<artifactId>ruoyi-vue-plus</artifactId>
|
||||||
<groupId>com.ruoyi</groupId>
|
<groupId>com.ruoyi</groupId>
|
||||||
<version>2.5.1</version>
|
<version>2.5.2</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
@ -12,5 +12,7 @@ public class CloudConstant {
|
|||||||
*/
|
*/
|
||||||
public final static String CLOUD_STORAGE_CONFIG_KEY = "sys.oss.cloudStorageService";
|
public final static String CLOUD_STORAGE_CONFIG_KEY = "sys.oss.cloudStorageService";
|
||||||
|
|
||||||
|
public final static String DEFAULT_CONTENT_TYPE = "application/octet-stream";
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ public interface ICloudStorageService {
|
|||||||
* @param path 文件路径,包含文件名
|
* @param path 文件路径,包含文件名
|
||||||
* @return 返回http地址
|
* @return 返回http地址
|
||||||
*/
|
*/
|
||||||
UploadResult upload(byte[] data, String path);
|
UploadResult upload(byte[] data, String path, String contentType);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文件删除
|
* 文件删除
|
||||||
@ -48,7 +48,7 @@ public interface ICloudStorageService {
|
|||||||
* @param suffix 后缀
|
* @param suffix 后缀
|
||||||
* @return 返回http地址
|
* @return 返回http地址
|
||||||
*/
|
*/
|
||||||
UploadResult uploadSuffix(byte[] data, String suffix);
|
UploadResult uploadSuffix(byte[] data, String suffix, String contentType);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文件上传
|
* 文件上传
|
||||||
@ -57,7 +57,7 @@ public interface ICloudStorageService {
|
|||||||
* @param path 文件路径,包含文件名
|
* @param path 文件路径,包含文件名
|
||||||
* @return 返回http地址
|
* @return 返回http地址
|
||||||
*/
|
*/
|
||||||
UploadResult upload(InputStream inputStream, String path);
|
UploadResult upload(InputStream inputStream, String path, String contentType);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文件上传
|
* 文件上传
|
||||||
@ -66,5 +66,5 @@ public interface ICloudStorageService {
|
|||||||
* @param suffix 后缀
|
* @param suffix 后缀
|
||||||
* @return 返回http地址
|
* @return 返回http地址
|
||||||
*/
|
*/
|
||||||
UploadResult uploadSuffix(InputStream inputStream, String suffix);
|
UploadResult uploadSuffix(InputStream inputStream, String suffix, String contentType);
|
||||||
}
|
}
|
||||||
|
@ -34,22 +34,22 @@ public abstract class AbstractCloudStorageService implements ICloudStorageServic
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public abstract UploadResult upload(byte[] data, String path);
|
public abstract UploadResult upload(byte[] data, String path, String contentType);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public abstract void delete(String path);
|
public abstract void delete(String path);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UploadResult upload(InputStream inputStream, String path) {
|
public UploadResult upload(InputStream inputStream, String path, String contentType) {
|
||||||
byte[] data = IoUtil.readBytes(inputStream);
|
byte[] data = IoUtil.readBytes(inputStream);
|
||||||
return this.upload(data, path);
|
return this.upload(data, path, contentType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public abstract UploadResult uploadSuffix(byte[] data, String suffix);
|
public abstract UploadResult uploadSuffix(byte[] data, String suffix, String contentType);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public abstract UploadResult uploadSuffix(InputStream inputStream, String suffix);
|
public abstract UploadResult uploadSuffix(InputStream inputStream, String suffix, String contentType);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public abstract void afterPropertiesSet() throws Exception;
|
public abstract void afterPropertiesSet() throws Exception;
|
||||||
|
@ -50,12 +50,12 @@ public class AliyunCloudStorageServiceImpl extends AbstractCloudStorageService i
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UploadResult upload(byte[] data, String path) {
|
public UploadResult upload(byte[] data, String path, String contentType) {
|
||||||
return upload(new ByteArrayInputStream(data), path);
|
return upload(new ByteArrayInputStream(data), path, contentType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UploadResult upload(InputStream inputStream, String path) {
|
public UploadResult upload(InputStream inputStream, String path, String contentType) {
|
||||||
try {
|
try {
|
||||||
client.putObject(this.properties.getBucketName(), path, inputStream);
|
client.putObject(this.properties.getBucketName(), path, inputStream);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -75,13 +75,13 @@ public class AliyunCloudStorageServiceImpl extends AbstractCloudStorageService i
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UploadResult uploadSuffix(byte[] data, String suffix) {
|
public UploadResult uploadSuffix(byte[] data, String suffix, String contentType) {
|
||||||
return upload(data, getPath(this.properties.getPrefix(), suffix));
|
return upload(data, getPath(this.properties.getPrefix(), suffix), contentType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UploadResult uploadSuffix(InputStream inputStream, String suffix) {
|
public UploadResult uploadSuffix(InputStream inputStream, String suffix, String contentType) {
|
||||||
return upload(inputStream, getPath(this.properties.getPrefix(), suffix));
|
return upload(inputStream, getPath(this.properties.getPrefix(), suffix), contentType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package com.ruoyi.oss.service.impl;
|
package com.ruoyi.oss.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.ruoyi.oss.constant.CloudConstant;
|
||||||
import com.ruoyi.oss.entity.UploadResult;
|
import com.ruoyi.oss.entity.UploadResult;
|
||||||
import com.ruoyi.oss.enumd.CloudServiceEnumd;
|
import com.ruoyi.oss.enumd.CloudServiceEnumd;
|
||||||
import com.ruoyi.oss.enumd.PolicyType;
|
import com.ruoyi.oss.enumd.PolicyType;
|
||||||
@ -58,17 +60,17 @@ public class MinioCloudStorageServiceImpl extends AbstractCloudStorageService im
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UploadResult upload(byte[] data, String path) {
|
public UploadResult upload(byte[] data, String path, String contentType) {
|
||||||
return upload(new ByteArrayInputStream(data), path);
|
return upload(new ByteArrayInputStream(data), path, contentType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UploadResult upload(InputStream inputStream, String path) {
|
public UploadResult upload(InputStream inputStream, String path, String contentType) {
|
||||||
try {
|
try {
|
||||||
minioClient.putObject(PutObjectArgs.builder()
|
minioClient.putObject(PutObjectArgs.builder()
|
||||||
.bucket(properties.getBucketName())
|
.bucket(properties.getBucketName())
|
||||||
.object(path)
|
.object(path)
|
||||||
.contentType("application/octet-stream")
|
.contentType(StrUtil.blankToDefault(contentType, CloudConstant.DEFAULT_CONTENT_TYPE))
|
||||||
.stream(inputStream, inputStream.available(), -1)
|
.stream(inputStream, inputStream.available(), -1)
|
||||||
.build());
|
.build());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -91,13 +93,13 @@ public class MinioCloudStorageServiceImpl extends AbstractCloudStorageService im
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UploadResult uploadSuffix(byte[] data, String suffix) {
|
public UploadResult uploadSuffix(byte[] data, String suffix, String contentType) {
|
||||||
return upload(data, getPath("", suffix));
|
return upload(data, getPath("", suffix), contentType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UploadResult uploadSuffix(InputStream inputStream, String suffix) {
|
public UploadResult uploadSuffix(InputStream inputStream, String suffix, String contentType) {
|
||||||
return upload(inputStream, getPath("", suffix));
|
return upload(inputStream, getPath("", suffix), contentType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -53,7 +53,7 @@ public class QcloudCloudStorageServiceImpl extends AbstractCloudStorageService i
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UploadResult upload(byte[] data, String path) {
|
public UploadResult upload(byte[] data, String path, String contentType) {
|
||||||
// 腾讯云必需要以"/"开头
|
// 腾讯云必需要以"/"开头
|
||||||
if (!path.startsWith("/")) {
|
if (!path.startsWith("/")) {
|
||||||
path = "/" + path;
|
path = "/" + path;
|
||||||
@ -80,13 +80,13 @@ public class QcloudCloudStorageServiceImpl extends AbstractCloudStorageService i
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UploadResult uploadSuffix(byte[] data, String suffix) {
|
public UploadResult uploadSuffix(byte[] data, String suffix, String contentType) {
|
||||||
return upload(data, getPath(this.properties.getPrefix(), suffix));
|
return upload(data, getPath(this.properties.getPrefix(), suffix), contentType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UploadResult uploadSuffix(InputStream inputStream, String suffix) {
|
public UploadResult uploadSuffix(InputStream inputStream, String suffix, String contentType) {
|
||||||
return upload(inputStream, getPath(this.properties.getPrefix(), suffix));
|
return upload(inputStream, getPath(this.properties.getPrefix(), suffix), contentType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -60,7 +60,7 @@ public class QiniuCloudStorageServiceImpl extends AbstractCloudStorageService im
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UploadResult upload(byte[] data, String path) {
|
public UploadResult upload(byte[] data, String path, String contentType) {
|
||||||
try {
|
try {
|
||||||
Response res = uploadManager.put(data, path, token);
|
Response res = uploadManager.put(data, path, token);
|
||||||
if (!res.isOK()) {
|
if (!res.isOK()) {
|
||||||
@ -86,13 +86,13 @@ public class QiniuCloudStorageServiceImpl extends AbstractCloudStorageService im
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UploadResult uploadSuffix(byte[] data, String suffix) {
|
public UploadResult uploadSuffix(byte[] data, String suffix, String contentType) {
|
||||||
return upload(data, getPath(this.properties.getPrefix(), suffix));
|
return upload(data, getPath(this.properties.getPrefix(), suffix), contentType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UploadResult uploadSuffix(InputStream inputStream, String suffix) {
|
public UploadResult uploadSuffix(InputStream inputStream, String suffix, String contentType) {
|
||||||
return upload(inputStream, getPath(this.properties.getPrefix(), suffix));
|
return upload(inputStream, getPath(this.properties.getPrefix(), suffix), contentType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -59,7 +59,7 @@ public class SysOssServiceImpl extends ServicePlusImpl<SysOssMapper, SysOss> imp
|
|||||||
ICloudStorageService storage = OssFactory.instance();
|
ICloudStorageService storage = OssFactory.instance();
|
||||||
UploadResult uploadResult;
|
UploadResult uploadResult;
|
||||||
try {
|
try {
|
||||||
uploadResult = storage.uploadSuffix(file.getBytes(), suffix);
|
uploadResult = storage.uploadSuffix(file.getBytes(), suffix, file.getContentType());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new CustomException("文件读取异常!!!", e);
|
throw new CustomException("文件读取异常!!!", e);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user