Browse Source

!313 修复上传七牛云无mime type问题
Merge pull request !313 from 石溪/master

芋道源码 2 years ago
parent
commit
44249e43dd
14 changed files with 15 additions and 14 deletions
  1. 1 1
      yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/FileClient.java
  2. 1 1
      yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/db/DBFileClient.java
  3. 1 1
      yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/ftp/FtpFileClient.java
  4. 1 1
      yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/local/LocalFileClient.java
  5. 2 1
      yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/s3/S3FileClient.java
  6. 1 1
      yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/sftp/SftpFileClient.java
  7. 1 1
      yudao-framework/yudao-spring-boot-starter-file/src/test/java/cn/iocoder/yudao/framework/file/core/client/ftp/FtpFileClientTest.java
  8. 1 1
      yudao-framework/yudao-spring-boot-starter-file/src/test/java/cn/iocoder/yudao/framework/file/core/client/local/LocalFileClientTest.java
  9. 1 1
      yudao-framework/yudao-spring-boot-starter-file/src/test/java/cn/iocoder/yudao/framework/file/core/client/s3/S3FileClientTest.java
  10. 1 1
      yudao-framework/yudao-spring-boot-starter-file/src/test/java/cn/iocoder/yudao/framework/file/core/client/sftp/SftpFileClientTest.java
  11. 1 1
      yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileConfigServiceImpl.java
  12. 1 1
      yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileServiceImpl.java
  13. 1 1
      yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/file/FileConfigServiceImplTest.java
  14. 1 1
      yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/file/FileServiceTest.java

+ 1 - 1
yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/FileClient.java

@@ -22,7 +22,7 @@ public interface FileClient {
      * @return 完整路径,即 HTTP 访问地址
      * @throws Exception 上传文件时,抛出 Exception 异常
      */
-    String upload(byte[] content, String path) throws  Exception;
+    String upload(byte[] content, String path, String type) throws  Exception;
 
     /**
      * 删除文件

+ 1 - 1
yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/db/DBFileClient.java

@@ -21,7 +21,7 @@ public class DBFileClient extends AbstractFileClient<DBFileClientConfig> {
     }
 
     @Override
-    public String upload(byte[] content, String path) {
+    public String upload(byte[] content, String path, String type) {
         getDao().insert(getId(), path, content);
         // 拼接返回路径
         return super.formatFileUrl(config.getDomain(), path);

+ 1 - 1
yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/ftp/FtpFileClient.java

@@ -38,7 +38,7 @@ public class FtpFileClient extends AbstractFileClient<FtpFileClientConfig> {
     }
 
     @Override
-    public String upload(byte[] content, String path) {
+    public String upload(byte[] content, String path, String type) {
         // 执行写入
         String filePath = getFilePath(path);
         String fileName = FileUtil.getName(filePath);

+ 1 - 1
yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/local/LocalFileClient.java

@@ -25,7 +25,7 @@ public class LocalFileClient extends AbstractFileClient<LocalFileClientConfig> {
     }
 
     @Override
-    public String upload(byte[] content, String path) {
+    public String upload(byte[] content, String path, String type) {
         // 执行写入
         String filePath = getFilePath(path);
         FileUtil.writeBytes(content, filePath);

+ 2 - 1
yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/s3/S3FileClient.java

@@ -82,10 +82,11 @@ public class S3FileClient extends AbstractFileClient<S3FileClientConfig> {
     }
 
     @Override
-    public String upload(byte[] content, String path) throws Exception {
+    public String upload(byte[] content, String path, String type) throws Exception {
         // 执行上传
         client.putObject(PutObjectArgs.builder()
                 .bucket(config.getBucket()) // bucket 必须传递
+                .contentType(type)
                 .object(path) // 相对路径作为 key
                 .stream(new ByteArrayInputStream(content), content.length, -1) // 文件内容
                 .build());

+ 1 - 1
yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/sftp/SftpFileClient.java

@@ -31,7 +31,7 @@ public class SftpFileClient extends AbstractFileClient<SftpFileClientConfig> {
     }
 
     @Override
-    public String upload(byte[] content, String path) {
+    public String upload(byte[] content, String path, String type) {
         // 执行写入
         String filePath = getFilePath(path);
         File file = FileUtils.createTempFile(content);

+ 1 - 1
yudao-framework/yudao-spring-boot-starter-file/src/test/java/cn/iocoder/yudao/framework/file/core/client/ftp/FtpFileClientTest.java

@@ -25,7 +25,7 @@ public class FtpFileClientTest {
         // 上传文件
         String path = IdUtil.fastSimpleUUID() + ".jpg";
         byte[] content = ResourceUtil.readBytes("file/erweima.jpg");
-        String fullPath = client.upload(content, path);
+        String fullPath = client.upload(content, path, "image/jpeg");
         System.out.println("访问地址:" + fullPath);
         if (false) {
             byte[] bytes = client.getContent(path);

+ 1 - 1
yudao-framework/yudao-spring-boot-starter-file/src/test/java/cn/iocoder/yudao/framework/file/core/client/local/LocalFileClientTest.java

@@ -19,7 +19,7 @@ public class LocalFileClientTest {
         // 上传文件
         String path = IdUtil.fastSimpleUUID() + ".jpg";
         byte[] content = ResourceUtil.readBytes("file/erweima.jpg");
-        String fullPath = client.upload(content, path);
+        String fullPath = client.upload(content, path, "image/jpeg");
         System.out.println("访问地址:" + fullPath);
         client.delete(path);
     }

+ 1 - 1
yudao-framework/yudao-spring-boot-starter-file/src/test/java/cn/iocoder/yudao/framework/file/core/client/s3/S3FileClientTest.java

@@ -101,7 +101,7 @@ public class S3FileClientTest {
         // 上传文件
         String path = IdUtil.fastSimpleUUID() + ".jpg";
         byte[] content = ResourceUtil.readBytes("file/erweima.jpg");
-        String fullPath = client.upload(content, path);
+        String fullPath = client.upload(content, path, "image/jpeg");
         System.out.println("访问地址:" + fullPath);
         // 读取文件
         if (true) {

+ 1 - 1
yudao-framework/yudao-spring-boot-starter-file/src/test/java/cn/iocoder/yudao/framework/file/core/client/sftp/SftpFileClientTest.java

@@ -23,7 +23,7 @@ public class SftpFileClientTest {
         // 上传文件
         String path = IdUtil.fastSimpleUUID() + ".jpg";
         byte[] content = ResourceUtil.readBytes("file/erweima.jpg");
-        String fullPath = client.upload(content, path);
+        String fullPath = client.upload(content, path, "image/jpeg");
         System.out.println("访问地址:" + fullPath);
         if (false) {
             byte[] bytes = client.getContent(path);

+ 1 - 1
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileConfigServiceImpl.java

@@ -230,7 +230,7 @@ public class FileConfigServiceImpl implements FileConfigService {
         this.validateFileConfigExists(id);
         // 上传文件
         byte[] content = ResourceUtil.readBytes("file/erweima.jpg");
-        return fileClientFactory.getFileClient(id).upload(content, IdUtil.fastSimpleUUID() + ".jpg");
+        return fileClientFactory.getFileClient(id).upload(content, IdUtil.fastSimpleUUID() + ".jpg", "image/jpeg");
     }
 
     @Override

+ 1 - 1
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileServiceImpl.java

@@ -52,7 +52,7 @@ public class FileServiceImpl implements FileService {
         // 上传到文件存储器
         FileClient client = fileConfigService.getMasterFileClient();
         Assert.notNull(client, "客户端(master) 不能为空");
-        String url = client.upload(content, path);
+        String url = client.upload(content, path, type);
 
         // 保存到数据库
         FileDO file = new FileDO();

+ 1 - 1
yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/file/FileConfigServiceImplTest.java

@@ -240,7 +240,7 @@ public class FileConfigServiceImplTest extends BaseDbUnitTest {
         // mock 获得 Client
         FileClient fileClient = mock(FileClient.class);
         when(fileClientFactory.getFileClient(eq(id))).thenReturn(fileClient);
-        when(fileClient.upload(any(), any())).thenReturn("https://www.iocoder.cn");
+        when(fileClient.upload(any(), any(), any())).thenReturn("https://www.iocoder.cn");
 
         // 调用,并断言
         assertEquals("https://www.iocoder.cn", fileConfigService.testFileConfig(id));

+ 1 - 1
yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/file/FileServiceTest.java

@@ -79,7 +79,7 @@ public class FileServiceTest extends BaseDbUnitTest {
         FileClient client = mock(FileClient.class);
         when(fileConfigService.getMasterFileClient()).thenReturn(client);
         String url = randomString();
-        when(client.upload(same(content), same(path))).thenReturn(url);
+        when(client.upload(same(content), same(path), same("image/jpeg"))).thenReturn(url);
         when(client.getId()).thenReturn(10L);
         String name = "单测文件名";
         // 调用