• Post Reply Bookmark Topic Watch Topic
  • New Topic

Copy a File from Client to Network Server  RSS feed

 
Steve Dyke
Ranch Hand
Posts: 1739
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On a JSP I have an Input "file" box. What do I do in my class to take this client file and write it to the network file system. I have done this before using a JSF but I am needing to do it using a JSP. My web session is running as a user that has authority to the network file system.

My issue is getting the client file in bytes then use FileOutputStream to write to destination.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See the JSP FAQ.
 
Steve Dyke
Ranch Hand
Posts: 1739
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a way to read the contents of a client file(bytes) at the client(javascript), store this in a parameter, send this parameter to servlet so the servlet could use FileOutputStream to place the file on our network?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For security reasons, Javascript can not access a client's hard drive.

HTML provides an input control of type "file" which allows the user to select a file and post it to the server as part of a multi-part encoded form. By design, there is very little you can do to interact with this control from your Javascript code.

On the server, you can use one of several third party products to parse this multipart form and work with the uploaded file.

See:
http://faq.javaranch.com/java/FileUpload
For more information on file uploads.
 
Steve Dyke
Ranch Hand
Posts: 1739
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have got the commons_fileupload to work using a normal form submit. I would prefer to use the jQuery.post. Is this possible? I can't seem to find the right key to a successful post.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ajax cannot normally support file uploads. The official jQuery Form Plugin will allow you to perform a file upload using Ajax (sort of, behind the scenes it creates an invisible iframe which is used to upload the file data rather than XHR).
 
Steve Dyke
Ranch Hand
Posts: 1739
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My challenge seems comlicated to me.

I need a page(in it's own window) called from a parent page. The form will ask for sheet size and a file path(there can be up to five sets). Once submitted I need my servlet to determine how many sets are submited. Call a class that makes a connection to a remote database. Plug in the sheet sizes and path strings to where the uploaded files will be stored into database file fields. Then process the uploaded files and place them in specific folders on our network system. Then close the child page.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!