• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Copy a File from Client to Network Server

 
Ranch Hand
Posts: 2206
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See the JSP FAQ.
 
Steve Dyke
Ranch Hand
Posts: 2206
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2206
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2206
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Lookout! Runaway whale! Hide behind this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic