Solved

Uploading images & Image manipulation

Posted on 2004-10-14
6
198 Views
Last Modified: 2010-04-01
Hi everyone

What I am trying to do is this:

I want to have a JSP where the user browses for an image, and then clicks a submit button, I then want the selected image to be uploaded and stored...

My questions are:

1 - Can the image be stored in a MySQL database or does it have to be uploaded to a directory

2 - Is there a way to manipulate the image and make thumbnails etc in a Servlet?

3 - Is there a java API for doing things like this (if yes any chance of a url)?

Many thanks

Kris


0
Comment
Question by:KrisM82
  • 4
  • 2
6 Comments
 
LVL 35

Expert Comment

by:TimYates
ID: 12317925
1) I would store the image in a directory.  It makes it easier to show the image to the user (via an IMG html tag), and makes it easier to backup your data (as your database doesn't contain loads of BLOB fields)
2) Yeah, sure...  Load the image in to a BufferedImage, call getScaledInstance, and write the image back out again using the JPG compression routines (http://javaalmanac.com/egs/javax.imageio/BasicImageRead.html and http://javaalmanac.com/egs/javax.imageio/JpegWrite.html)
3) See 2  ;-)

Tim
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12317932
Oh, and http://javaalmanac.com/egs/java.awt.image/CreateTxImage.html for the "making it smaller" bit ;-)
0
 
LVL 35

Accepted Solution

by:
TimYates earned 20 total points
ID: 12318011
Oh yeah -- hehe, what a lot of typing for 20 points ;-)

When you upload an image, I would use File.getTempFile to give the file a temoprary name (that is unique to your images directory), and then store this name in the database (instead of the image itself), along with the original name of the image -- then you won't get problems with 2 people uploading an image with the same name...

Otherwise, you will get problems with user A uploading "new.gif" and user B uploading "new.gif", as one will overwrite the other...

Tim
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:KrisM82
ID: 12351816
Cool thanks for the help exactly what I was looking for :0)
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12355468
Good luck! :-)

Tim
0
 

Author Comment

by:KrisM82
ID: 12380282
Having a few problems with this still, any chance you could give me a hand if i post the source code?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

OpenVPN is a great open source VPN server that is capable of providing quick and easy VPN access to your network on the cheap.  By default the software is configured to allow open access to your network.  But what if you want to restrict users to on…
Facing problems with you memory card? Cannot access your memory card? All stored data, images, videos are lost? If these are your questions...than this small article might help you out in retrieving your lost or inaccessible data.
A short film showing how OnPage and Connectwise integration works.
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

943 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

1 Experts available now in Live!

Get 1:1 Help Now