Currently I am using JSP and Struts to build a website. There is a requirement that user can upload a file by just typing in the local path of the file. When submitting the local path of the file, server will automatically retrieve the file and upload it. Is it possible to achieve this goal?
Asked
Active
Viewed 540 times
0
-
No, it's not possible. The server cannot (a) initiate arbitrary file uploads from the client (imagine the security risks) or even (b) pre-populate a file upload dialog (same reasons). – Dave Newton Dec 16 '14 at 18:32
1 Answers
0
All you can do is to ask the client to supply you with the file. You cannot simply make the server retrieve a file from a client, as the client does not expose its file system.
For file uploads using JSPs refer to: http://www.tutorialspoint.com/jsp/jsp_file_uploading.htm
I hope this could help, please specify your problem in more detail if you need further input.
You could also be interessted in: https://blueimp.github.io/jQuery-File-Upload/basic.html

JaEb
- 76
- 6
-
I want to know how exactly the uploading mechanism works. For example, you press the select button and a window pops up. You can select a file in your local computer and then upload it. Is it the same with only providing a path like C:\myfolder\myfile.csv? – user3870168 Dec 16 '14 at 16:08
-
What happens is, that on the client side a HTTP Post request, containing the file in the messagebody, is created and sent to the server. When you select a file in the pop up window, the browser uses the path specified there to create the http request. So it is basically equivalent to specifying a path to a file, just more convenient. I'm not aware of a method which allows you to specify a local path in an input field and then upload the file specified, but it is most likely possible using javascript by generating the http request yourself. – JaEb Dec 16 '14 at 16:26
-
For technical details on form-based uploads refer to: http://stackoverflow.com/questions/8659808/how-does-http-file-upload-work You could also design you backend as a RESTful service and upload the file without html-forms, but javascript. – JaEb Dec 16 '14 at 16:27