Write Image to Memory Instead of to Disk

  • Thread starter Emery Z. Balint Jr.
  • Start date
E

Emery Z. Balint Jr.

Hello all,

Is there any way of writing an image file (JPEG and/or PNG) to memory
instead of to the hard drive? Here's what I'm trying to do. Users can upload
an image to a Web site. I grab their image (form multipart/data) and if it's
ok, I write it to the drive, if it's not, I delete the file.

The problem is that I must write it to the hard drive, and if criteria is
not met, deletion isn't always possible. So writing that JPEG or PNG file to
memory would be much more convenient as I could probably just null the
variable. Is this possible? Thanks for any push in the right direction!

M.
*****
Sun Certified Programmer
http://www.websamba.com/javarobotics/
E-stronomy - Astronomical Resources
http://www.websamba.com/e-stronomy/
 
V

VisionSet

Emery Z. Balint Jr. said:
Hello all,

Is there any way of writing an image file (JPEG and/or PNG) to memory
instead of to the hard drive? Here's what I'm trying to do. Users can upload
an image to a Web site. I grab their image (form multipart/data) and if it's
ok, I write it to the drive, if it's not, I delete the file.

The problem is that I must write it to the hard drive, and if criteria is
not met, deletion isn't always possible. So writing that JPEG or PNG file to
memory would be much more convenient as I could probably just null the
variable. Is this possible? Thanks for any push in the right direction!

read up in the API under:

javax.imageio.ImageIO.setUseCache(false);
 
R

Roedy Green

The problem is that I must write it to the hard drive, and if criteria is
not met, deletion isn't always possible. So writing that JPEG or PNG file to
memory would be much more convenient as I could probably just null the
variable. Is this possible? Thanks for any push in the right direction!

write it to a byte array. Ask the File I/O amanuensis for how.
See http://mindprod.com/fileio.html
 
R

RGonzalez

Yes,

When you upload an image, store it in a javabean of property type
java.io.ByteArrayOutputStream and store the bean in session. You can do
whatever you want with it without having to stream it out to disk.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top