Results 1 to 6 of 6
  1. #1
    rajeshwari_ib is offline Member
    Join Date
    Dec 2009
    Posts
    1
    Rep Power
    0

    Default retrieve file containg image from database

    Hi all,


    I have doc file containing images and i stored it in to database Blob type.
    I retrieved that file from database and written the content to new doc file.
    but the resultant doc file is not containing images instead it is containing binay data of images. But i want doc file with original images how to solve it
    please help me for this.

  2. #2
    FON
    FON is offline Senior Member
    Join Date
    Dec 2009
    Location
    Belgrade, Serbia
    Posts
    368
    Rep Power
    5

    Default

    Storing images in DB is not very good solution.

    First it is not natural to store a lot of data in DB that has to be retrieved later.

    Second when you store it, you cannot open img file easily from out of DB.

    Mostly used approach is to store images on file system, and store their names in DB tables as regular txt or varchar column type.
    You have only to match the data in the column with file name in your file system in proper way.

    regards :)

  3. #3
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,006
    Rep Power
    20

    Default

    Quote Originally Posted by FON View Post
    Storing images in DB is not very good solution.

    First it is not natural to store a lot of data in DB that has to be retrieved later.

    Second when you store it, you cannot open img file easily from out of DB.

    Mostly used approach is to store images on file system, and store their names in DB tables as regular txt or varchar column type.
    You have only to match the data in the column with file name in your file system in proper way.

    regards :)
    Couldn't disagree more.
    You store data in a database. Images are data.

    Now, some DBs are not as good as others at this. I'm not entirely sure it's possible in Access, for example. But Oracle, SQLServer, Postgres work.

    As for reading it out of the db? That's just as easy as reading it from a file.

    The other advantage of having it in the db is data integrity. The db will now be handling all your data, and not just part of it, so the integrity will be far easier to maintain.

    As for lots of data. That's what DBs are for!

    Anyway, it appears the OP is storing a .doc file (ie word document), that contains images, and not an image file itself.

    So, for the OP, how are you writing this to the db from the doc, and how are you reading it back?

  4. #4
    FON
    FON is offline Senior Member
    Join Date
    Dec 2009
    Location
    Belgrade, Serbia
    Posts
    368
    Rep Power
    5

    Default

    Tolls thank you very much for your post,
    i have discussion on this topic with my colleagues
    and most things you have written are correct.

    This is what forums is about - rethinking and finding good second opinion:)

    DB admins told me that this things has to be considered
    on file-system vs. DB topic:

    1) Cost and capacity - do you use your own DB server or is it hosted somewhere, let's say ISP gives you 50MB in some MySQL DB.
    There are folder issues depending on your OS - MAX physical number of files in folder, so you have to make a logic to map filenames from many different dirs to actual files in DB...

    2) Speed - indexed paths in File System with help of lucene can increase speed when you compare it to DB file writing. There are many type of file systems for different OSs, some or better to store bigger files...

    Rethink how often you do replication and backup of your huge DB if files are in it. Everyone knows hot to copy files to another location and it is fast.
    If you backup again, it is even faster - just use SKIP when same file is
    to be copied again


    3) security - definitely better if files are in DB.
    You don't have to think about file and folder permissions,
    specially if server is not yours (you use ISP)

    Delete, insert, update problems:
    If you delete some record in DB that has file associated with it,
    you are responsible for writing code that deletes the file from file-system,
    or you will have orphan files.
    On contrary if file is in DB, you can use it in SQL queries if you need it
    and use cascades to delete it easily when parent is deleted.

    Think about possibility to move application from Windows to Linux
    and problems you may have with different file system nature, permissions...
    if you use file system to store your files


    Looking forward to here more opinions from forum members
    and hope we will solve your problem in further posts ;)

  5. #5
    lolu is offline Member
    Join Date
    Nov 2009
    Location
    Abuja, Nigeria
    Posts
    15
    Rep Power
    0

    Default

    Quote Originally Posted by Tolls View Post
    Couldn't disagree more.
    You store data in a database. Images are data.

    Now, some DBs are not as good as others at this. I'm not entirely sure it's possible in Access, for example. But Oracle, SQLServer, Postgres work.

    As for reading it out of the db? That's just as easy as reading it from a file.

    The other advantage of having it in the db is data integrity. The db will now be handling all your data, and not just part of it, so the integrity will be far easier to maintain.

    As for lots of data. That's what DBs are for!

    Anyway, it appears the OP is storing a .doc file (ie word document), that contains images, and not an image file itself.

    So, for the OP, how are you writing this to the db from the doc, and how are you reading it back?
    I was begining to think about the task of data movement from one file system to the other and all the details involved(based what FON said)...You made a lot of sense here Tolls.

  6. #6
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,006
    Rep Power
    20

    Default

    Good points, FON.
    The places I've worked tend to have their own DBs, and control over hosting, so much of the stuff you mention hasn't affected me. These things are never carved in stone...:)

Similar Threads

  1. Retrieve Image From Hard Disk
    By sayan751 in forum AWT / Swing
    Replies: 3
    Last Post: 02-20-2009, 03:29 PM
  2. image insertion into database
    By abhiN in forum JDBC
    Replies: 4
    Last Post: 01-05-2009, 05:09 AM
  3. How to store/retrieve PNG image in/from RMS
    By jason-nexFIT-mobileXware in forum CLDC and MIDP
    Replies: 0
    Last Post: 09-10-2008, 04:01 AM
  4. Retriving image from database
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-09-2008, 08:41 PM
  5. passing image file to database
    By abhiN in forum Advanced Java
    Replies: 2
    Last Post: 01-21-2008, 06:30 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •