Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to refer uploaded file

 
Sai Shrawan
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,

i searched a lot for this one before posting this.

my requirement in brief:
i)User selects an image.
ii)I need to read the image
iii)Store it in server's file system. (Not in database as BLOB)
iv)The image selected by the user should be made visible in a page. so i need to give a reference to the image uploaded thru src attribute in img tag of the webpage.

now the problem is how to accomplish the iii) and iv) steps. i'm able to read the file from client machine thru MultiPart concept and i'm able to accomplish the first 2 steps.

the problem becomes tricky bcoz all the clients shud be able to see the image and we need to set the src attribute such a way that it is global and not specific to any client/server's file system.

i tried to give relative path, but its not working.

am i missing something which is very simple.
help is appreciated
[ June 14, 2005: Message edited by: Bear Bibeault ]
 
Senthil B Kumar
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
How are you organizing the storage of your user uploaded files. Means, where exactly (in which folder) is those files stored.

Is it along with the webpart of the application ? , ie along with the META-INF folder and currently how are you accessing it and what is the problem you are facing ?
 
Sai Shrawan
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanx for the quick reply.

i'll make my pblm clearer. i'm able to read the file from the client machine ... means i'm getting the bytes.
now my question is how to write those bytes to a file and where to store it so that it can be referenced by all the clients.
 
Senthil B Kumar
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i guess we need information like where are you now currently storing your file (ie in which folder exactly).

For example, you can create an UserFiles folder in the Web part, along with the WEB-INF folder. Then write your files to this folder, note that it is better to use a relative path (relative to the context root of the application) to mention where to write the files.

Basically its relative and relative to context root of the application.
 
Sai Shrawan
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanx for the hint.

this is what i was looking for, where to store the client file.
stored here:request.getSession().getServletContext().getRealPath("/")

and then used relative path as u said for referring the file on server.

thanx again
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic