feat: 企标宣贯-带文件导出
This commit is contained in:
@@ -26,4 +26,13 @@ public interface IOSSFileService extends IService<OSSFile> {
|
||||
void updateFileInfo(List<OSSFile> ossFileList);
|
||||
|
||||
OSSFile uploadLocalOfCos(MultipartFile mf, String bizPath, String state, String cut);
|
||||
|
||||
|
||||
/**
|
||||
* 获取文件内容
|
||||
* @param file
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
byte[] getMinioFileContent(OSSFile file) throws Exception;
|
||||
}
|
||||
|
||||
+24
@@ -19,7 +19,9 @@ import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
@@ -330,4 +332,26 @@ public class OSSFileServiceImpl extends ServiceImpl<OSSFileMapper, OSSFile> impl
|
||||
oSSFile.setUrl(null);
|
||||
return oSSFile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getMinioFileContent(OSSFile file) throws Exception {
|
||||
String fileUrl = file.getUrl();
|
||||
String minioUrl = MinioUtil.getMinioUrl();
|
||||
minioUrl = minioUrl + MinioUtil.getBucketName() + "/";
|
||||
String url = fileUrl.replace(minioUrl, "");
|
||||
|
||||
try (InputStream inputStream = MinioUtil.getMinioFile(MinioUtil.getBucketName(), url);
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream()
|
||||
) {
|
||||
byte[] buf = new byte[1024];
|
||||
int len;
|
||||
while ((len = inputStream.read(buf)) > 0) {
|
||||
outputStream.write(buf, 0, len);
|
||||
}
|
||||
return outputStream.toByteArray();
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user