This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
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

need to upload a file in server path using servlets and retrieve that path in url format?

 
Suresh Entropy
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all... I need to upload a file in server path and again i need to retrieve that file path into URL so that i show the file in jsp page using that converted URL... Suggestions and examples please..

regards,
Suresh
 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can upload an image (or any file really) using an HTTP POST request with a multipart/form-data content type. Handling such a request on the server-side can be made easier by using a library like Apache Commons FileUpload. Once you've extracted the image data from the request you can store it in anyway you like. You could for instance place it in a shared image folder as a file and serve it to incoming HTTP requests from that location.
 
Suresh Entropy
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am already done with uploading the file in my local location, i need to have it in my server location is one thing, and another i need to fetch that server location to get converted to URL. I need this conversion in order to view that uploaded file via URL.
 
Nam Ha Minh
Ranch Hand
Posts: 502
Eclipse IDE Firefox Browser Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Suresh Entropy wrote:I am already done with uploading the file in my local location, i need to have it in my server location is one thing, and another i need to fetch that server location to get converted to URL. I need this conversion in order to view that uploaded file via URL.

I think you should place your uploaded files somewhere on your server so that the files can be accessed through HTTP.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As a matter of security, servers are restricted in terms of the file paths they are allowed to access and URLs never reflect the absolute file location on the server but are always translated.

It would be a huge security hole if a URL could access an arbitrary file path.

this subject is frequently addressed in this forum.

Bill
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic