diff --git a/fi/shkd-fi-fi/src/main/java/shkd/fi/fi/task/impl/OAInvoiceImpl.java b/fi/shkd-fi-fi/src/main/java/shkd/fi/fi/task/impl/OAInvoiceImpl.java index fc485b9..8504d7f 100644 --- a/fi/shkd-fi-fi/src/main/java/shkd/fi/fi/task/impl/OAInvoiceImpl.java +++ b/fi/shkd-fi-fi/src/main/java/shkd/fi/fi/task/impl/OAInvoiceImpl.java @@ -26,10 +26,7 @@ import shkd.fi.fi.util.LogBillUtils; import shkd.fi.fi.util.ParamsUtils; import shkd.fi.fi.util.SFTPConnectUtil; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.UnsupportedEncodingException; +import java.io.*; import java.net.URLDecoder; import java.net.URLEncoder; import java.rmi.RemoteException; @@ -109,8 +106,18 @@ public class OAInvoiceImpl { path = URLDecoder.decode(path,"UTF-8"); path = FilePathUtil.dealPath(path,"attach"); InputStream inputStream = FileServiceFactory.getAttachmentFileService().getInputStream(path); - FileInputStream fileInputStream = (FileInputStream) inputStream; - boolean flag = SFTPConnectUtil.uploadFile("/usr/local/nginx/html/", fileInputStream, filename, sftp); + String suffix = filename.substring(filename.lastIndexOf(".")); + File tempFile = File.createTempFile(filename,suffix); + tempFile.deleteOnExit(); + try (FileOutputStream outputStream = new FileOutputStream(tempFile)) { + byte[] buffer = new byte[1024]; + int bytesRead; + while ((bytesRead = inputStream.read(buffer)) != -1) { + outputStream.write(buffer, 0, bytesRead); + } + } + + boolean flag = SFTPConnectUtil.uploadFile("/usr/local/nginx/html/", tempFile, sftp,filename); if(flag){ String filenameEn = URLEncoder.encode(filename); @@ -120,6 +127,10 @@ public class OAInvoiceImpl { log.info("url参数转义后:"+url); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); + } catch (FileNotFoundException e) { + throw new RuntimeException(e); + } catch (IOException e) { + throw new RuntimeException(e); } } diff --git a/fi/shkd-fi-fi/src/main/java/shkd/fi/fi/util/SFTPConnectUtil.java b/fi/shkd-fi-fi/src/main/java/shkd/fi/fi/util/SFTPConnectUtil.java index c2018e6..dd1002e 100644 --- a/fi/shkd-fi-fi/src/main/java/shkd/fi/fi/util/SFTPConnectUtil.java +++ b/fi/shkd-fi-fi/src/main/java/shkd/fi/fi/util/SFTPConnectUtil.java @@ -88,11 +88,11 @@ public class SFTPConnectUtil { * @return boolean */ public static boolean uploadFile(String directory, File uploadFile, - ChannelSftp sftp) { + ChannelSftp sftp,String fileName) { try { // 进入指定目录 sftp.cd(directory); - sftp.put(new FileInputStream(uploadFile), uploadFile.getName()); + sftp.put(new FileInputStream(uploadFile), fileName); } catch (FileNotFoundException e) { logger.error("uploadFile -- FileNotFoundException:" + e.toString()); return false; @@ -292,7 +292,7 @@ public class SFTPConnectUtil { /** * 判断对象是否为空 * - * @param str + * @param * @return boolean */ public static boolean isEmpty(Object obj) {