Uploading images & Image manipulation

Posted on 2004-10-14
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


Question by:KrisM82
  • 4
  • 2
LVL 35

Expert Comment

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 ( and
3) See 2  ;-)

LVL 35

Expert Comment

ID: 12317932
Oh, and for the "making it smaller" bit ;-)
LVL 35

Accepted Solution

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...

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline


Author Comment

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

Expert Comment

ID: 12355468
Good luck! :-)


Author Comment

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

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

In this article, I will show you HOW TO: Suppress Configuration Issues and Warnings Alert displayed in Summary status for ESXi 6.5 after enabling SSH or ESXi Shell.
For cloud, the “train has left the station” and in the Microsoft ERP & CRM world, that means the next generation of enterprise software from Microsoft is here: Dynamics 365 is Microsoft’s new integrated business solution that unifies CRM and ERP fun…
Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

743 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

12 Experts available now in Live!

Get 1:1 Help Now