aspose file tools*
The moose likes Other Open Source Projects and the fly likes Trying uplod in FTP but unable to get File Name it returns null Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Trying uplod in FTP but unable to get File Name it returns null" Watch "Trying uplod in FTP but unable to get File Name it returns null" New topic
Author

Trying uplod in FTP but unable to get File Name it returns null

Ajay Nanda
Greenhorn

Joined: Oct 27, 2013
Posts: 7
My project basically is to upload multiple files in ftp server and create directory as per user input and strores file in it, but when i run the project i i get the file name returns NULL, please help how i can get that


Here is my Code

FTPFileUplaod.java


Create Directory



uploadFile.jsp

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42919
    
  68
Where are you getting nulls? What, exactly, happens if you run this code?
Ajay Nanda
Greenhorn

Joined: Oct 27, 2013
Posts: 7
while(iterator.hasNext()){
FileItem item = (FileItem) iterator.next();

fileName = item.getName();
System.out.println("File :" +fileName);

Here i getting the name of the fileName = value

But i add the file name in following code :

File uploadedFile = new File(fileName);
System.out.println("++++++++++++++++++++++++++++");
System.out.println("Uploaded File :" + uploadedFile.getName());

The name of uplaodedFile.getName() returns NULL.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42919
    
  68
A FileItem is not a File object (nor an actual file). Once the upload has finished, you now need to create a file to store the uploaded data permanently (assuming that that is what you want to do). Note that in order to store files in a web app you need to use absolute paths, not relative paths. Be sure to read the javadocs of FileItem.getName() about this.
Ajay Nanda
Greenhorn

Joined: Oct 27, 2013
Posts: 7
What should i do ?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42919
    
  68
Save the uploaded file - *if* that is what you want to do; you haven't told us. The Apache Commons FileUpload site has an extensive user guide and FAQ that tells you all you need to know.
Ajay Nanda
Greenhorn

Joined: Oct 27, 2013
Posts: 7
I made following changes in my code



When i run this i got the File Name but i unable store the file in to my ftp server location

I get the following exeception



Please help how can store uploaded to files to ftp server?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42919
    
  68
You can't use a FileInputStream because the file does not exist. Please follow my earlier advice to read the user guide of the FileUpload library to learn how it actually works.
Ajay Nanda
Greenhorn

Joined: Oct 27, 2013
Posts: 7
I already read the user guide of the FileUpload library and used in my code but i am getting the result what i want

You are not getting my question.

How i can store the uploaded files in the diretcory in my ftp server
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42919
    
  68
I already read the user guide of the FileUpload library and used in my code

I see nothing in the code you posted where you would handle the uploaded data. As I pointed out, using File and FileInputStream is wrong. You need to get an InputStream from the uploaded data that you can pass to the storeFile method.

A further problem (which I mentioned in an earlier post) is using FileItem.getName(). So, again: read its javadocs, particularly what it says about the behavior of some browsers. You can't use it directly as the name of the file to store via FTP - you need to process it first to make sure it is a valid file name, and not a full path.
Ajay Nanda
Greenhorn

Joined: Oct 27, 2013
Posts: 7
I made following changes on my code



but i getting same exception



Please provide some codes to upload multiples files from web browser to ftp server
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42919
    
  68
You're still not doing this:
I see nothing in the code you posted where you would handle the uploaded data. As I pointed out, using File and FileInputStream is wrong. You need to get an InputStream from the uploaded data that you can pass to the storeFile method.


And it looks like you're not doing this, either:
A further problem (which I mentioned in an earlier post) is using FileItem.getName(). So, again: read its javadocs, particularly what it says about the behavior of some browsers. You can't use it directly as the name of the file to store via FTP - you need to process it first to make sure it is a valid file name, and not a full path.


Do you understand what both these points mean? Unless and until you do, you have little chance of making this work.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Trying uplod in FTP but unable to get File Name it returns null