|
|
@@ -2,6 +2,7 @@ package me.zhengjie.appapi.util;
|
|
|
|
|
|
import java.io.ByteArrayInputStream;
|
|
|
import java.io.File;
|
|
|
+import java.io.FileInputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
|
import java.util.Iterator;
|
|
|
@@ -121,7 +122,7 @@ public class FileUploadUtil {
|
|
|
// FileUtils.writeByteArrayToFile(fullPath, b);
|
|
|
return imagePath;
|
|
|
} catch (Exception e) {
|
|
|
- log.info("上传图片失败:" + e.getLocalizedMessage());
|
|
|
+ log.error("上传图片失败:" + e.getLocalizedMessage());
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
@@ -155,7 +156,7 @@ public class FileUploadUtil {
|
|
|
uploadFile(imagePath, contentType, partFile.getInputStream());
|
|
|
return imagePath;
|
|
|
} catch (Exception e) {
|
|
|
- log.info("上传图片失败:" + e.getLocalizedMessage());
|
|
|
+ log.error("上传图片失败:" + e.getLocalizedMessage());
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
@@ -252,7 +253,7 @@ public class FileUploadUtil {
|
|
|
fileHandle.uploadFileStream(fileHandlevo);
|
|
|
return imagePath;
|
|
|
} catch (Exception e) {
|
|
|
- log.info("上传图片失败:" + e.getLocalizedMessage());
|
|
|
+ log.error("上传图片失败:" + e.getLocalizedMessage());
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
@@ -294,7 +295,7 @@ public class FileUploadUtil {
|
|
|
bis.close();
|
|
|
return filePath;
|
|
|
} catch (Exception e) {
|
|
|
- log.info("上传图片失败:" + e.getLocalizedMessage());
|
|
|
+ log.error("上传图片失败:" + e.getLocalizedMessage());
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
@@ -383,30 +384,34 @@ public class FileUploadUtil {
|
|
|
if (html == null) {
|
|
|
return null;
|
|
|
}
|
|
|
-
|
|
|
String uploadPath = AppConfigInfo.APP_UPLOAD_PATH;
|
|
|
// 拼接文件路径
|
|
|
String fileName = UUIDGenerator.uuid() + ".pdf";
|
|
|
String path = businessNo + "/" + StepStatusEnum.getType(orderId) + "/" + fileName;
|
|
|
- String filePath = uploadPath + path;
|
|
|
+ String sourceFilePath = uploadPath + path;
|
|
|
+ InputStream inputStream = null;
|
|
|
try {
|
|
|
// File file, String data, Charset charset
|
|
|
- HtmlConvertPdf.createPdfFile(html, filePath);
|
|
|
+ HtmlConvertPdf.createPdfFile(html, sourceFilePath);
|
|
|
+ inputStream = new FileInputStream(sourceFilePath);
|
|
|
// 这里需要把转换完成的删除掉
|
|
|
String contentType = "application/pdf";
|
|
|
// 通过流上传
|
|
|
// fileHandle.uploadFilePath(path, filePath, contentType);
|
|
|
FileHandleVo fileHandlevo = new FileHandleVo();
|
|
|
- fileHandlevo.setFilePath(filePath);
|
|
|
- fileHandlevo.setSourceFilePath(filePath);
|
|
|
+ fileHandlevo.setFilePath(path);
|
|
|
+ fileHandlevo.setSourceFilePath(sourceFilePath);
|
|
|
fileHandlevo.setContentType(contentType);
|
|
|
+ fileHandlevo.setInputStream(inputStream);
|
|
|
fileHandle.uploadFileStream(fileHandlevo);
|
|
|
// 这个删除文件留给具体的上传处理
|
|
|
-// FileUtils.deleteQuietly(new File(filePath));
|
|
|
+ FileUtils.deleteQuietly(new File(sourceFilePath));
|
|
|
return path;
|
|
|
} catch (Exception e) {
|
|
|
- log.info("转换pdf失败:" + e.getLocalizedMessage());
|
|
|
+ log.error("转换pdf失败:" + e.getLocalizedMessage());
|
|
|
return null;
|
|
|
+ } finally {
|
|
|
+ IoUtil.close(inputStream);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -436,12 +441,25 @@ public class FileUploadUtil {
|
|
|
try {
|
|
|
return fileHandle.getPreviewUrl(fileKey);
|
|
|
} catch (Exception e) {
|
|
|
- log.info("图片预览失败:" + e.getLocalizedMessage());
|
|
|
+ log.error("图片预览失败:" + e.getLocalizedMessage());
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
-
|
|
|
+ /**
|
|
|
+ * 通过文件id得到文件流
|
|
|
+ * @param fileId
|
|
|
+ * @return
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ public static byte[] getByte(String fileId) throws Exception{
|
|
|
+ try {
|
|
|
+ return fileHandle.getByte(fileId);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("得到文件流失败:" + e.getLocalizedMessage());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
/**
|
|
|
* 得到文件名称
|
|
|
*
|