|
@@ -45,7 +45,7 @@ import java.util.Map;
|
|
|
@Configuration
|
|
@Configuration
|
|
|
public class FileUtils {
|
|
public class FileUtils {
|
|
|
|
|
|
|
|
- private static String BASE_DIR = "kll/uploads/";
|
|
|
|
|
|
|
+ private static String BASE_DIR = "kll/uploads/steel";
|
|
|
|
|
|
|
|
//oss客户端连接
|
|
//oss客户端连接
|
|
|
private static OSS ossclient = null;
|
|
private static OSS ossclient = null;
|
|
@@ -1364,58 +1364,5 @@ public class FileUtils {
|
|
|
return byteImg;
|
|
return byteImg;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 测试
|
|
|
|
|
- public static void main(String[] args) throws FileNotFoundException {
|
|
|
|
|
- //阿里云OSS账号自行到阿里云官网申请
|
|
|
|
|
- String ossEndpoint = "XXX";
|
|
|
|
|
- String accessId = "XXX";
|
|
|
|
|
- String accessKey = "XXX";
|
|
|
|
|
- String bucketName = "test";
|
|
|
|
|
- // 初始化OSSClient
|
|
|
|
|
-// OSS ossClient = AliyunOSSClientUtil.getOssClient(ossEndpoint, accessId, accessKey);
|
|
|
|
|
- OSS ossClient = FileUtils.getOssClient(ossEndpoint, accessId, accessKey);
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- //测试创建多级目录
|
|
|
|
|
- /*String tmpDir = "upload/2023/01/11/";
|
|
|
|
|
- String folder = createFolder(ossClient, bucketName, tmpDir);
|
|
|
|
|
- System.out.println("folder:"+folder);*/
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- //测试删除文件
|
|
|
|
|
- /*String key="upload/2023/01/11/xxx.pdf";
|
|
|
|
|
- deleteObject(ossClient,bucketName,key);*/
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- //测试上传文件
|
|
|
|
|
- /*String pathAndname = "C:\\Users\\Administrator\\Desktop\\测试文件上传\\xxx.pdf";
|
|
|
|
|
- File file = new File(pathAndname);
|
|
|
|
|
- //原始文件名:带后缀
|
|
|
|
|
- String oldfilename = file.getName();
|
|
|
|
|
- //新文件名:带后缀
|
|
|
|
|
- String newfilename = "9065df0f3ab72419b36d2dec088e11d6.pdf";//可以自行生成随机唯一文件名
|
|
|
|
|
- String newpath = "C:\\Users\\Administrator\\Desktop\\upload\\2023\\01\\11\\";
|
|
|
|
|
- String ossPath = newpath + newfilename;
|
|
|
|
|
- InputStream is = new FileInputStream(file);
|
|
|
|
|
- String absolutePath = uploadFileOss(ossClient, bucketName, ossPath, is, newfilename);
|
|
|
|
|
- System.out.println("absolutePath:"+absolutePath);*/
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- //测试获取文件url
|
|
|
|
|
- /*String key="upload/2023/01/11/9065df0f3ab72419b36d2dec088e11d6.pdf";
|
|
|
|
|
- String url = getUrl(ossClient, bucketName, key);
|
|
|
|
|
- System.out.println("url:"+url);*/
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- //测试获取上传对象
|
|
|
|
|
- /*String key = "upload/2023/01/11/9065df0f3ab72419b36d2dec088e11d6.pdf";
|
|
|
|
|
- getObject(ossClient, bucketName, key);*/
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- //测试下载文件到本地
|
|
|
|
|
- /*String key = "upload/2023/01/11/9065df0f3ab72419b36d2dec088e11d6.pdf";
|
|
|
|
|
- String localFilePath = "C:\\Users\\Administrator\\Desktop\\oss-download\\xxx.pdf";
|
|
|
|
|
- downloadFileOss(ossClient, bucketName, key, localFilePath);*/
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|