When i try to upload UploadedFile
object content To FTP server
[That its value get from [t:inputFileUpload] component]
The loading indicator in my web browser play and will not stop
When debug i found that my come freezes in a line
ftp.storeFile(destFilePath, inputStream);
However i try 3 methods (shown in code) to upload
BUT still all methods not working
Controller method that UploadedFile to FTPServer
public static String uploadFileToFTPServer
(String ftpServerIP, String userName, String password,UploadedFile uploadedFile) {
String destFilePath = null;
FTPClient ftp = new FTPClient();
ftp.addProtocolCommandListener(new PrintCommandListener(
new PrintWriter(System.out)));
try {
// Method 1
byte[] fileBytesContent = uploadedFile.getBytes();
ByteArrayInputStream inputStream = new ByteArrayInputStream(fileBytesContent);
// Method 2
// InputStream inputStream = uploadedFile.getInputStream();
// Method 3
// InputStream inputStreamContent = uploadedFile.getInputStream();
// BufferedInputStream inputStream = new BufferedInputStream(inputStreamContent);
destFilePath = uploadedFile.getName() ;
// ftp server
ftp.connect(ftpServerIP);
ftp.login(userName, password);
ftp.setFileType(FTPClient.BINARY_FILE_TYPE);
ftp.setFileTransferMode(FTPClient.BINARY_FILE_TYPE);
ftp.storeFile(destFilePath, inputStream);
inputStream.close();
ftp.logout();
} catch (Exception e) {
destFilePath = null;
e.printStackTrace();
} finally {
try {
ftp.disconnect();
} catch (IOException e) {
e.printStackTrace();
}
}
return destFilePath;
}
Note
When Freeze i check the my FTP server
And see the file name BUT its size = zero !!
Then after some seconds this file will disappeared