How to convert JPEG to binary using Java & save into database

Discussion in 'Java' started by himaloy, Oct 4, 2006.

  1. himaloy

    himaloy Guest

    Hi,

    i need to know how can i convert a JPEG grey scale image into binary
    file using Java and save that file into a database for example MySql...

    is it hard to do?

    Thnks..
     
    himaloy, Oct 4, 2006
    #1
    1. Advertising

  2. himaloy

    Baby Lion Guest

    write it to an array of byte
    then save it to blob of DB
    you can search blob in jdk api document
    himaloy 写é“:

    > Hi,
    >
    > i need to know how can i convert a JPEG grey scale image into binary
    > file using Java and save that file into a database for example MySql...
    >
    > is it hard to do?
    >
    > Thnks..
     
    Baby Lion, Oct 4, 2006
    #2
    1. Advertising

  3. Hi,

    I would recommend storing the files on the file system, and store the
    pointers to the files in the database instead of a blob (unless you're
    storing thumbnails or files relatively small in size). You can store
    something like server/folder/filename in mySQL for every file, which
    should give your app enough info to pull the file when need be.

    -cheers,
    Manish
     
    Manish Pandit, Oct 4, 2006
    #3
  4. himaloy

    Simon Brooke Guest

    in message <>, Manish
    Pandit ('') wrote:

    > I would recommend storing the files on the file system, and store the
    > pointers to the files in the database instead of a blob (unless you're
    > storing thumbnails or files relatively small in size). You can store
    > something like server/folder/filename in mySQL for every file, which
    > should give your app enough info to pull the file when need be.


    H'mmmm... this is what I currently do. It's simple and 90% of the time it
    works. But if the file in the file system gets moved or deleted, it
    breaks. Actually shoving the data into the database has the advantage that
    the database looks after referential integrity (i.e., in this case, the
    image doesn't get deleted unless the record gets dropped).

    --
    (Simon Brooke) http://www.jasmine.org.uk/~simon/

    IMHO, there aren't enough committed Christians, but that's care
    in the community for you. -- Ben Evans
     
    Simon Brooke, Oct 4, 2006
    #4
  5. Simon Brooke wrote:
    > But if the file in the file system gets moved or deleted, it
    > breaks. Actually shoving the data into the database has the advantage that
    > the database looks after referential integrity (i.e., in this case, the
    > image doesn't get deleted unless the record gets dropped).
    >


    In that case the file system should be controlled - and people/process
    should be well aware of the consequences of moving the files around. If
    you do want to take the blob route, do ensure to load test the system,
    as I am quite sure blob selects will slow down your system
    considerably, based on the image size, access frequency and access
    mechanism (filtered vs. lookup..).

    -cheers,
    Manish
     
    Manish Pandit, Oct 4, 2006
    #5
  6. himaloy

    steve Guest

    On Thu, 5 Oct 2006 01:46:33 +0800, Baby Lion wrote
    (in article <>):

    > write it to an array of byte
    > then save it to blob of DB
    > you can search blob in jdk api document
    > himaloy 写é“:
    >
    >> Hi,
    >>
    >> i need to know how can i convert a JPEG grey scale image into binary
    >> file using Java and save that file into a database for example MySql...
    >>
    >> is it hard to do?
    >>
    >> Thnks..

    >


    lame idea number 1.
     
    steve, Oct 4, 2006
    #6
  7. himaloy

    steve Guest

    On Thu, 5 Oct 2006 02:29:54 +0800, Manish Pandit wrote
    (in article <>):

    > Hi,
    >
    > I would recommend storing the files on the file system, and store the
    > pointers to the files in the database instead of a blob (unless you're
    > storing thumbnails or files relatively small in size). You can store
    > something like server/folder/filename in mySQL for every file, which
    > should give your app enough info to pull the file when need be.
    >
    > -cheers,
    > Manish
    >


    lame idea number 2
     
    steve, Oct 4, 2006
    #7
  8. himaloy

    steve Guest

    On Thu, 5 Oct 2006 04:24:38 +0800, Simon Brooke wrote
    (in article <>):

    > in message <>, Manish
    > Pandit ('') wrote:
    >
    >> I would recommend storing the files on the file system, and store the
    >> pointers to the files in the database instead of a blob (unless you're
    >> storing thumbnails or files relatively small in size). You can store
    >> something like server/folder/filename in mySQL for every file, which
    >> should give your app enough info to pull the file when need be.

    >
    > H'mmmm... this is what I currently do. It's simple and 90% of the time it
    > works. But if the file in the file system gets moved or deleted, it
    > breaks. Actually shoving the data into the database has the advantage that
    > the database looks after referential integrity (i.e., in this case, the
    > image doesn't get deleted unless the record gets dropped).
    >
    >


    finally some sense.
     
    steve, Oct 4, 2006
    #8
  9. himaloy

    steve Guest

    On Thu, 5 Oct 2006 01:21:48 +0800, himaloy wrote
    (in article <>):

    > Hi,
    >
    > i need to know how can i convert a JPEG grey scale image into binary
    > file using Java and save that file into a database for example MySql...
    >
    > is it hard to do?
    >
    > Thnks..
    >


    just convert to a grey scale, then stream it out to a blob.

    if possible leave it in colour, unless you are absolutely sure you will never
    need the original image again.

    You can always pre-process between the database & the user.

    What I actually do is store the images & a thumb nail, in the record.
    (pre-process a thumb nail , make it perhaps no more than 5-10% of the
    original image)
    then for the user pull the thumbnails over to the user & if the user selects
    the picture THEN bring over the full image.

    Steve
     
    steve, Oct 4, 2006
    #9
  10. "steve" <> wrote in message
    news:...
    > On Thu, 5 Oct 2006 01:21:48 +0800, himaloy wrote
    > (in article <>):
    >
    >> Hi,
    >>
    >> i need to know how can i convert a JPEG grey scale image into binary
    >> file using Java and save that file into a database for example MySql...
    >>
    >> is it hard to do?
    >>
    >> Thnks..
    >>

    >
    > just convert to a grey scale, then stream it out to a blob.


    The OP appears to already have a gray scale image and wants to know how save
    it to a database.

    Your prior message called writing the image to a blob a lame idea without
    explaining, which does not help the OP or any other readers also looking for
    information. I'd like to hear why you think streaming is now so much better
    than writing the byte array directly.

    Matt Humphrey http://www.iviz.com/
     
    Matt Humphrey, Oct 5, 2006
    #10
  11. "Manish Pandit" <> wrote in message
    news:...
    > Simon Brooke wrote:
    >> But if the file in the file system gets moved or deleted, it
    >> breaks. Actually shoving the data into the database has the advantage
    >> that
    >> the database looks after referential integrity (i.e., in this case, the
    >> image doesn't get deleted unless the record gets dropped).
    >>

    >
    > In that case the file system should be controlled - and people/process
    > should be well aware of the consequences of moving the files around. If
    > you do want to take the blob route, do ensure to load test the system,
    > as I am quite sure blob selects will slow down your system
    > considerably, based on the image size, access frequency and access
    > mechanism (filtered vs. lookup..).


    I've used the file system approach before and it's nice for getting
    something together quickly, but I've run into big trouble when the number of
    files is more than small. At about 50,000 files in a single folder the OS
    has a hard time finding things. I wouldn't recommend it for applications
    that have to scale.

    Matt Humphrey http://www.iviz.com/
     
    Matt Humphrey, Oct 5, 2006
    #11
  12. himaloy

    Simon Brooke Guest

    in message <>, Manish
    Pandit ('') wrote:

    > Simon Brooke wrote:
    >> But if the file in the file system gets moved or deleted, it
    >> breaks. Actually shoving the data into the database has the advantage
    >> that the database looks after referential integrity (i.e., in this case,
    >> the image doesn't get deleted unless the record gets dropped).

    >
    > In that case the file system should be controlled - and people/process
    > should be well aware of the consequences of moving the files around. If
    > you do want to take the blob route, do ensure to load test the system,
    > as I am quite sure blob selects will slow down your system
    > considerably, based on the image size, access frequency and access
    > mechanism (filtered vs. lookup..).


    Yup, but, case in point, I have an application that does this (images in
    file system, reference in database) which has been in use on a fair number
    of sites since 2000. When I distribute a new version, the easiest solution
    to doing an update is to delete the application directory and drop the new
    WAR file in place. However, this doesn't work because I store uploaded
    images, etc, in a subdirectory of the upload directory. This may not be
    the best thing to do, but it mostly works and I haven't fixed it.

    So to update one either needs to copy all the upload subdirectories out of
    the application, then stop and drop the application and install the new
    WAR, wait for it to unpack, and copy the contents of the upload
    directories back (which can be done with Tomcat with no server restart),
    or else unpack the new WAR into the old application directory overwriting
    its contents, which (a) doesn't work if you are replacing jar files in the
    WEB-INF/lib with new ones with different names (which I usually am), and
    (b) definitely does require a server restart.

    Every time I produce a new release we have this issue come up; if I did
    keep the actual image data (and XSL, and other uploaded content) in the
    database it wouldn't happen, and sooner or later I'm going to get round to
    making that change. I appreciate there may be performance issues, which I
    shall probably get around by caching.

    --
    (Simon Brooke) http://www.jasmine.org.uk/~simon/
    Iraq war: it's time for regime change...
    ... go now, Tony, while you can still go with dignity.
    [update 18 months after this .sig was written: it's still relevant]
     
    Simon Brooke, Oct 5, 2006
    #12
  13. himaloy

    himaloy Guest

    thanks everyone for your reply.
     
    himaloy, Oct 24, 2006
    #13
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lucas Cowald
    Replies:
    2
    Views:
    21,822
    Steve C. Orr [MVP, MCSD]
    Oct 15, 2003
  2. Lucas Cowald

    How to convert JPEG image into a binary data?

    Lucas Cowald, Oct 15, 2003, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    331
    Victor Garcia Aprea [MVP]
    Oct 19, 2003
  3. Lucas Cowald

    How to convert JPEG image into a binary data?

    Lucas Cowald, Oct 15, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    186
    Lucas Cowald
    Oct 15, 2003
  4. Lucas Cowald

    How to convert JPEG image into a binary data?

    Lucas Cowald, Oct 15, 2003, in forum: ASP .Net Mobile
    Replies:
    0
    Views:
    151
    Lucas Cowald
    Oct 15, 2003
  5. Lucas Cowald

    How to convert JPEG image into a binary data?

    Lucas Cowald, Oct 15, 2003, in forum: ASP .Net Security
    Replies:
    1
    Views:
    331
    Steve Jansen
    Oct 15, 2003
Loading...

Share This Page