| | |
| | | } else if (imageBase64.contains("data:application/octet-stream;base64,")) { |
| | | imageBase64 = imageBase64.replace("data:application/octet-stream;base64,", ""); |
| | | fileName += ".jpg"; |
| | | } else if (imageBase64.contains(".mp4") || imageBase64.contains(".MP4") || imageBase64.contains(".AVI") || imageBase64.contains(".avi") |
| | | || imageBase64.contains(".WMV") || imageBase64.contains(".wmv")) { |
| | | fileName += ".mp4"; |
| | | } else { |
| | | fileName += ".jpg"; |
| | | } |
| | |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | |
| | | public InputStream download(String fileName, String server, int port, String userName, String userPassword) { |
| | | InputStream is = null; |
| | | ByteArrayOutputStream bos = null; |
| | | ByteArrayInputStream fis = null; |
| | | FTPClient ftpClient = new FTPClient(); |
| | | try { |
| | | if (!ftpClient.isConnected()) { |
| | | ftpClient.connect(server, port); |
| | | } |
| | | ftpClient.login(userName, userPassword); |
| | | ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE); |
| | | ftpClient.enterLocalPassiveMode(); |
| | | int reply = ftpClient.getReplyCode(); |
| | | if (!FTPReply.isPositiveCompletion(reply)) { |
| | | ftpClient.disconnect(); |
| | | } |
| | | String f = new String( |
| | | (fileName).getBytes("GBK"), |
| | | FTP.DEFAULT_CONTROL_ENCODING); |
| | | is = ftpClient.retrieveFileStream(f);// 获取远程ftp上指定文件的InputStream |
| | | if (null == is) { |
| | | throw new FileNotFoundException(fileName); |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | logger.error("ftp通过文件名称获取远程文件流", e); |
| | | } finally { |
| | | try { |
| | | //closeConnect(ftpClient); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | } |