|
|
@ -5,6 +5,7 @@ import com.aliyun.oss.OSSClientBuilder; |
|
|
|
import com.tduck.cloud.storage.exception.StorageException; |
|
|
|
|
|
|
|
import java.io.ByteArrayInputStream; |
|
|
|
import java.io.File; |
|
|
|
import java.io.InputStream; |
|
|
|
|
|
|
|
/** |
|
|
@ -15,6 +16,7 @@ import java.io.InputStream; |
|
|
|
public class AliyunOssStorageService extends OssStorageService { |
|
|
|
|
|
|
|
private OSS client; |
|
|
|
private static final String baseDir = "survey"; |
|
|
|
|
|
|
|
public AliyunOssStorageService(OssStorageConfig config) { |
|
|
|
this.config = config; |
|
|
@ -30,23 +32,23 @@ public class AliyunOssStorageService extends OssStorageService { |
|
|
|
@Override |
|
|
|
public String upload(InputStream inputStream, String path) { |
|
|
|
try { |
|
|
|
client.putObject(config.getBucketName(), path, inputStream); |
|
|
|
client.putObject(config.getBucketName(), baseDir+ File.separator+path, inputStream); |
|
|
|
} catch (Exception e) { |
|
|
|
throw new StorageException("上传文件失败,请检查配置信息", e); |
|
|
|
} |
|
|
|
|
|
|
|
return config.getDomain() + "/" + path; |
|
|
|
return config.getDomain() + "/"+baseDir+ "/" + path; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public String upload(byte[] data, String path) { |
|
|
|
try { |
|
|
|
client.putObject(config.getBucketName(), path, new ByteArrayInputStream(data)); |
|
|
|
client.putObject(config.getBucketName(), baseDir+ File.separator+path, new ByteArrayInputStream(data)); |
|
|
|
} catch (Exception e) { |
|
|
|
throw new StorageException("上传文件失败,请检查配置信息", e); |
|
|
|
} |
|
|
|
|
|
|
|
return config.getDomain() + "/" + path; |
|
|
|
return config.getDomain() + "/"+ baseDir+"/" + path; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -60,6 +62,6 @@ public class AliyunOssStorageService extends OssStorageService { |
|
|
|
|
|
|
|
@Override |
|
|
|
public void delete(String path) { |
|
|
|
client.deleteObject(config.getBucketName(), path); |
|
|
|
client.deleteObject(config.getBucketName(), baseDir+ File.separator+path); |
|
|
|
} |
|
|
|
} |
|
|
|