This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

image not shows full path  RSS feed

 
deep raj
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i create a file type input button
when i upload a file from my pc it should be saved into mysql database
so i used this
request.getParameter("img");
then i insert it into database table

but when i open my table into MYSQL
i saw image name not full means it not show full path
what should i do now?

all over i want
when user signup and loads its photo
this photo must be displayed whenever he logins
 
Misha Ver
Ranch Hand
Posts: 470
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think it is good idea to store absolute paths. What if you migrate your app to another server? It is better to use relative path which is relative to the working directory of the application.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you wanting to store the image itself in the database, or the file path on the file system? If you are using a file upload control you will not be able to use getParameter().

Please explain your requirements in better detail.
 
deep raj
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
actually i want that when user upload its image
it must be shown in his profile when he again login


for this we store it into database
how ?

i used getParameter but it not show full path
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please read the JSP FAQ regarding file uploads. You cannot use getParameter() with a file upload.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And even if you could, it would be useless--it would be the path of the file on the *client* machine, not the server. And different browsers include different information in that path--some put the entire path (incorrect behavior), some just the filename. Save the file locally, save *that* path in the DB.
 
Mark E Hansen
Ranch Hand
Posts: 650
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When the image is uploaded, it needs to be saved on the server somewhere. You can either save the image file in the file system, then save the path to that file in your database, or just save the image itself in the database (then you don't need to worry about the path at all).

Then you can use an Image Servlet (there an article in the ServletsFaq that talks about this) to serve the image on later requests.
 
deep raj
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am not understanding
what you want to say
can anyone give me link or code
so that i can understand the thing
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In order to upload a file, the form needs to have enctype="multipart/form-data".

In order to process such a form on the server side, it's easiest to use a library that handles parsing the request parameters, for example, the Apache Commons FileUpload library.

The filename sent with the form is the name of the file on the client--in other words, if I'm upload a file to your site, the filename sent by my browser will be the filename on *my* system. It may or may not include complete path information (again, on *my* machine)--that behavior depends on the browser. The name of the file on *my* machine is useless to you.

Your application, on the *server* side, should save the file locally. *That* filename, including the path, is what you should store in your database, and use an image servlet as previously mentioned to send it back to a client. I'm not a fan of storing the images themselves in the database.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Again, this is all covered in the FAQ.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!