Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Upload

 
Dura Hurtado
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi , My would like upload a file to a server the example class which primefaces gives us is:

public class FileUploadController {

//private Logger logger = LoggerFactory.getLogger(FileUploadController.class);

public void handleFileUpload(FileUploadEvent event) {
// logger.info("Uploaded: {}", event.getFile().getFileName());

FacesMessage msg = new FacesMessage("Succesful", event.getFile().getFileName() + " is uploaded.");
FacesContext.getCurrentInstance().addMessage(null, msg);
}
}

┬┐Could I specified a folder on the server?

Thanks
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18272
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No you cannot. A Web server is not a File Server. When you upload a file from a web browser, what you are really doing is telling the browser to open the selected file and copy its contents to the HTTP(S) request data stream as part of a Multipart MIME FORM POST operation.

When the server receives that data stream, it's up to the application to figure out what to do with the data, and that may or may not include ever writing the data to a server file at all. And if you do write the data to a file, it's your application that defines what the filename written will be, whether it's to simply use the name that was passed from the client as part of the incoming request or some other name of your own devising.

If you want to make your server accept file upload locations, they, too are whatever and wherever your application wishes, as long as the app has the appropriate file and directory access tights. However, you should NEVER upload files into your WAR or into any of the J2EE server's directories. If you do, you may experience great pain.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic