• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Writing as a JPG file to disk

 
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Image gets written to disk and says file size also.

But am unable to see the image.

Some one clarify me on this.

I have Submitted the code.

What am doing is -

I am reading a blob as a byte and trying to save it to disk.

it saves to disk but unable to view the image.






 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What does "unable to view the image" mean? How are yoo trying to view it, and what happens?

Does the image file have the same size as the bytes array you're retrieving from the DB?

The call to "flush" should occur after the call to "write", not before.
 
ram kumar
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Am using the windows picture and fax viewer to view the file.

it gets saved to disk. it shows the same size as the source image that i uploaded to DB as a BLOB

Am not able to view the image in the picture and fax viewer application like the source image.

i did that with fout.flush() after fout.write().

Still this problem persists
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If this was my problem I would use a programmer's editor capable of showing the hex value of bytes to look at both the original jpg and the file recovered from the DB and written.

I bet you will see that something has corrupted the data recovered from the DB and it no longer resembles the original.

I use the ultraedit editor - best money I ever spent, but you may find that your existing editor can display byte values.

Bill
 
ram kumar
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

William Brogden wrote:If this was my problem I would use a programmer's editor capable of showing the hex value of bytes to look at both the original jpg and the file recovered from the DB and written.

I bet you will see that something has corrupted the data recovered from the DB and it no longer resembles the original.

I use the ultraedit editor - best money I ever spent, but you may find that your existing editor can display byte values.

Bill




Would you just help me in getting some links regarding this.

i google'd but still i need some more information of

1.how to convert a jpg to blob

2.update oracleDB with the blob.

----------

3. retrive the blob

4.save that in disk as a jpg file.
 
author
Posts: 3285
13
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

1.how to convert a jpg to blob
2.update oracleDB with the blob.
3. retrive the blob
4.save that in disk as a jpg file.


1.) Save as a ByteArray/ByteStream
2.) Simple Insert/Update statement will do it
3.) Simple select command will do it
4.) Write out as a ByteStream/ByteArray

You really need to look into the File I/O APIs an pay particular attention to _encoding_, e.g. Make sure your encoding is consistent throughout each stage. This article can help and make sure to look at our I/O FAQ
 
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It seems like you are assuming the bytes in the database are already in the proper format and simply write them to a file. There are many different image formats. Look at this info and see if you can create your own in memory image and write it to disk

http://java.sun.com/j2se/1.4.2/docs/guide/imageio/spec/imageio_guideTOC.fm.html
 
ram kumar
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

steve souza wrote:It seems like you are assuming the bytes in the database are already in the proper format and simply write them to a file. There are many different image formats. Look at this info and see if you can create your own in memory image and write it to disk

http://java.sun.com/j2se/1.4.2/docs/guide/imageio/spec/imageio_guideTOC.fm.html



Finally this code worked successfully !

I dont know what cases it will fail, but it worked Awesome for uploading images to jpg.

Max File Size uploaded is 25.7 kb

From windows file to oracle DB - Use PictureToBLOB2

From BLOB in DB to File at windows - Use BLOBToPicture2











Convert from BLOB to Picture

i used this code :






 
reply
    Bookmark Topic Watch Topic
  • New Topic