You've already forked FrameTour-BE
修改上传位置
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
package com.ycwl.basic.storage.adapters;
|
||||
|
||||
import com.ycwl.basic.storage.entity.StorageConfig;
|
||||
import com.ycwl.basic.storage.exceptions.UploadFileFailedException;
|
||||
import lombok.Setter;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
@@ -14,33 +12,33 @@ import java.util.Date;
|
||||
public abstract class AStorageAdapter implements IStorageAdapter {
|
||||
|
||||
@Override
|
||||
public String uploadFile(File file, String path, String filename) {
|
||||
public String uploadFile(File file, String ...path) {
|
||||
if (file == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
InputStream inputStream = new FileInputStream(file);
|
||||
return uploadFile(inputStream, path, filename);
|
||||
return uploadFile(inputStream, path);
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new UploadFileFailedException("文件不存在");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String uploadFile(MultipartFile file, String path, String filename) {
|
||||
public String uploadFile(MultipartFile file, String... path) {
|
||||
if (file == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
InputStream inputStream = file.getInputStream();
|
||||
return uploadFile(inputStream, path, filename);
|
||||
return uploadFile(inputStream, path);
|
||||
} catch (Exception e) {
|
||||
throw new UploadFileFailedException("文件上传失败");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUrlForUpload(String path, String filename) {
|
||||
return getUrlForUpload(path, filename, new Date(System.currentTimeMillis() + 1000 * 60 * 60));
|
||||
public String getUrlForUpload(String... path) {
|
||||
return getUrlForUpload(new Date(System.currentTimeMillis() + 1000 * 60 * 60), path);
|
||||
}
|
||||
}
|
||||
|
@@ -18,7 +18,7 @@ import java.net.URL;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
public class AliOssAdapter extends AStorageAdapter {
|
||||
final public class AliOssAdapter extends AStorageAdapter {
|
||||
private AliOssStorageConfig config;
|
||||
|
||||
@Override
|
||||
@@ -48,16 +48,16 @@ public class AliOssAdapter extends AStorageAdapter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String uploadFile(InputStream inputStream, String path, String filename) {
|
||||
public String uploadFile(InputStream inputStream, String ...path) {
|
||||
if (inputStream == null) {
|
||||
return null;
|
||||
}
|
||||
String fullPath = buildPath(path, filename);
|
||||
String fullPath = buildPath(path);
|
||||
OSS ossClient = getOssClient();
|
||||
try {
|
||||
PutObjectRequest putObjectRequest = new PutObjectRequest(config.getBucketName(), fullPath, inputStream);
|
||||
ossClient.putObject(putObjectRequest);
|
||||
return getUrl(path, filename);
|
||||
return getUrl(path);
|
||||
} catch (ClientException e) {
|
||||
throw new UploadFileFailedException("上传文件失败:" + e.getErrorMessage());
|
||||
}
|
||||
@@ -65,10 +65,10 @@ public class AliOssAdapter extends AStorageAdapter {
|
||||
|
||||
|
||||
@Override
|
||||
public boolean deleteFile(String path, String filename) {
|
||||
public boolean deleteFile(String... path) {
|
||||
OSS ossClient = getOssClient();
|
||||
try {
|
||||
ossClient.deleteObject(config.getBucketName(), buildPath(path, filename));
|
||||
ossClient.deleteObject(config.getBucketName(), buildPath(path));
|
||||
return true;
|
||||
} catch (ClientException e) {
|
||||
return false;
|
||||
@@ -76,14 +76,14 @@ public class AliOssAdapter extends AStorageAdapter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUrl(String path, String filename) {
|
||||
return config.getUrl() + "/" + buildPath(path, filename);
|
||||
public String getUrl(String... path) {
|
||||
return config.getUrl() + "/" + buildPath(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUrlForUpload(String path, String filename, Date expireDate) {
|
||||
public String getUrlForUpload(Date expireDate, String... path) {
|
||||
OSS ossClient = getOssClient();
|
||||
URL url = ossClient.generatePresignedUrl(config.getBucketName(), buildPath(path, filename), expireDate, HttpMethod.PUT);
|
||||
URL url = ossClient.generatePresignedUrl(config.getBucketName(), buildPath(path), expireDate, HttpMethod.PUT);
|
||||
return url.toString();
|
||||
}
|
||||
|
||||
|
@@ -11,11 +11,11 @@ import java.util.Map;
|
||||
public interface IStorageAdapter {
|
||||
void loadConfig(Map<String, String> config);
|
||||
void setConfig(StorageConfig config);
|
||||
String uploadFile(InputStream inputStream, String path, String filename);
|
||||
String uploadFile(File file, String path, String filename);
|
||||
String uploadFile(MultipartFile file, String path, String filename);
|
||||
boolean deleteFile(String path, String filename);
|
||||
String getUrl(String path, String filename);
|
||||
String getUrlForUpload(String path, String filename);
|
||||
String getUrlForUpload(String path, String filename, Date expireDate);
|
||||
String uploadFile(InputStream inputStream, String ...path);
|
||||
String uploadFile(File file, String ...path);
|
||||
String uploadFile(MultipartFile file, String ...path);
|
||||
boolean deleteFile(String ...path);
|
||||
String getUrl(String ...path);
|
||||
String getUrlForUpload(String ...path);
|
||||
String getUrlForUpload(Date expireDate, String ...path);
|
||||
}
|
||||
|
@@ -18,22 +18,22 @@ public class LocalStorageAdapter extends AStorageAdapter{
|
||||
}
|
||||
|
||||
@Override
|
||||
public String uploadFile(InputStream inputStream, String path, String filename) {
|
||||
public String uploadFile(InputStream inputStream, String... path) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteFile(String path, String filename) {
|
||||
public boolean deleteFile(String... path) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUrl(String path, String filename) {
|
||||
public String getUrl(String... path) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUrlForUpload(String path, String filename, Date expireDate) {
|
||||
public String getUrlForUpload(Date expireDate, String... path) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user