|
@@ -1,6 +1,7 @@
|
|
package com.siwei.file.service;
|
|
package com.siwei.file.service;
|
|
|
|
|
|
import java.io.InputStream;
|
|
import java.io.InputStream;
|
|
|
|
+
|
|
import com.alibaba.nacos.common.utils.IoUtils;
|
|
import com.alibaba.nacos.common.utils.IoUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
@@ -16,8 +17,7 @@ import com.siwei.common.core.utils.file.FileTypeUtils;
|
|
* @author siwei-zhx
|
|
* @author siwei-zhx
|
|
*/
|
|
*/
|
|
@Service
|
|
@Service
|
|
-public class FastDfsSysFileServiceImpl implements ISysFileService
|
|
|
|
-{
|
|
|
|
|
|
+public class FastDfsSysFileServiceImpl implements ISysFileService {
|
|
/**
|
|
/**
|
|
* 域名或本机访问地址
|
|
* 域名或本机访问地址
|
|
*/
|
|
*/
|
|
@@ -35,27 +35,17 @@ public class FastDfsSysFileServiceImpl implements ISysFileService
|
|
* @throws Exception
|
|
* @throws Exception
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
- public String uploadFile(MultipartFile file) throws Exception
|
|
|
|
- {
|
|
|
|
|
|
+ public String uploadFile(MultipartFile file) throws Exception {
|
|
InputStream inputStream = null;
|
|
InputStream inputStream = null;
|
|
- try
|
|
|
|
- {
|
|
|
|
|
|
+ try {
|
|
inputStream = file.getInputStream();
|
|
inputStream = file.getInputStream();
|
|
StorePath storePath = storageClient.uploadFile(inputStream, file.getSize(), FileTypeUtils.getExtension(file), null);
|
|
StorePath storePath = storageClient.uploadFile(inputStream, file.getSize(), FileTypeUtils.getExtension(file), null);
|
|
return domain + "/" + storePath.getFullPath();
|
|
return domain + "/" + storePath.getFullPath();
|
|
- }
|
|
|
|
- catch (Exception e)
|
|
|
|
- {
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
throw new RuntimeException("FastDfs Failed to upload file", e);
|
|
throw new RuntimeException("FastDfs Failed to upload file", e);
|
|
- }
|
|
|
|
- finally
|
|
|
|
- {
|
|
|
|
|
|
+ } finally {
|
|
IoUtils.closeQuietly(inputStream);
|
|
IoUtils.closeQuietly(inputStream);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
|
- public String[] uploadFileV1(MultipartFile file) throws Exception {
|
|
|
|
- return new String[0];
|
|
|
|
- }
|
|
|
|
}
|
|
}
|