Solved

Uploading images & Image manipulation

Posted on 2004-10-14
6
203 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
netstat -a in AIX unix 8 48
love6 challenge java 31 133
How to Make JSP Pages Responsive ? details are below 3 904
eclipse buid path vs tomcat lib path 10 34
Learn how to PXE Boot both BIOS & UEFI machines with DHCP Policies and Custom Vendor Classes
The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

856 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