add:修改ocr回调文件存储
This commit is contained in:
@@ -32,6 +32,10 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
import com.adc.da.sys.util.LoginUserUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
@@ -155,17 +159,24 @@ public class OCRRestfulServiceImpl implements OCRRestfulService {
|
||||
//首先将文件保存至本地
|
||||
String saveWordFilePath=null;
|
||||
String saveWordFileName=null;
|
||||
logger.info("将文件保存至本地");
|
||||
if(wordFile!=null && !wordFile.isEmpty()){
|
||||
saveWordFileName=UUIDUtils.randomUUID20()+"_"+wordFile.getOriginalFilename();
|
||||
saveWordFilePath=ocrFilePath+saveWordFileName;
|
||||
FileUtils.copyInputStreamToFile(wordFile.getInputStream(),new File(saveWordFilePath));
|
||||
logger.info(saveWordFilePath);
|
||||
//FileUtils.copyInputStreamToFile(wordFile.getInputStream(),new File(saveWordFilePath));
|
||||
savePic(wordFile.getInputStream(),saveWordFilePath);
|
||||
logger.info("word存储完成");
|
||||
}
|
||||
String saveJsonFilePath=null;
|
||||
String saveJsonFileName=null;
|
||||
if(jsonFile!=null && !jsonFile.isEmpty()){
|
||||
saveJsonFileName=UUIDUtils.randomUUID20()+"_"+jsonFile.getOriginalFilename();
|
||||
saveJsonFilePath=ocrFilePath+saveJsonFileName;
|
||||
FileUtils.copyInputStreamToFile(jsonFile.getInputStream(),new File(saveJsonFilePath));
|
||||
logger.info(saveJsonFilePath);
|
||||
//FileUtils.copyInputStreamToFile(jsonFile.getInputStream(),new File(saveJsonFilePath));
|
||||
savePic(jsonFile.getInputStream(),saveJsonFilePath);
|
||||
logger.info("Json存储完成");
|
||||
}
|
||||
//开始将文件保存至数据库中
|
||||
if(StringUtils.isNotEmpty(saveWordFilePath) && StringUtils.isNotEmpty(saveJsonFilePath)){
|
||||
@@ -186,4 +197,40 @@ public class OCRRestfulServiceImpl implements OCRRestfulService {
|
||||
return "{\"result\":\"error:File does not exist\"}";//文件不存在
|
||||
}
|
||||
}
|
||||
|
||||
private void savePic(InputStream inputStream, String filePath) {
|
||||
|
||||
OutputStream os = null;
|
||||
try {
|
||||
// 2、保存到临时文件
|
||||
// 1K的数据缓冲
|
||||
byte[] bs = new byte[1024];
|
||||
// 读取到的数据长度
|
||||
int len;
|
||||
// 输出的文件流保存到本地文件
|
||||
|
||||
File tempFile = new File(ocrFilePath);
|
||||
if (!tempFile.exists()) {
|
||||
tempFile.mkdirs();
|
||||
}
|
||||
os = new FileOutputStream(filePath);
|
||||
// 开始读取
|
||||
while ((len = inputStream.read(bs)) != -1) {
|
||||
os.write(bs, 0, len);
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
// 完毕,关闭所有链接
|
||||
try {
|
||||
os.close();
|
||||
inputStream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user