Solved

Uploading images & Image manipulation

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

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

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 (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. 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