MySQL: Storing files (images/pdf) in a table

Results 1 to 5 of 5

Thread: MySQL: Storing files (images/pdf) in a table

  1. #1
    Join Date
    Dec 1969
    Posts
    2

    Default MySQL: Storing files (images/pdf) in a table

    As the title suggests I am having difficulty storing files in a table. <BR><BR>I am using the insert statement <BR>"insert into Files (file) values (&#039;c: est.jpg&#039;)", and I am not recieving an error, however, I am not able to pull the image back out of the database, nor am I am to confirm that the image is in there in the first place.<BR><BR>Is it possible to store binaries in a MySQL table, if it is, is the insert statement I am using acceptable and how does one get the files back out, more specifically, how would I link to them from an asp so a person can see them in a browser.<BR><BR>Thank you.<BR><BR>jamitch<BR>

  2. #2
    Join Date
    Dec 1969
    Posts
    96,118

    Default That code sure won't do it

    That&#039;s just storing a *STRING* with the value <BR> c: est.jpg<BR>into the field.<BR><BR>Which, incidentally, is *FAR* the superior way to store images, in the first place.<BR><BR>Getting images out of DBs for use in further pages is a real pain in the ***. Not to mention slow and a big load on the DB server. <BR><BR>So just change the "file" field in that table to type VARCHAR and store the file names, instead. You *will* be much happier in the long run.<BR><BR>

  3. #3
    Join Date
    Dec 1969
    Posts
    11,247

    Default I agree With Bill

    You don&#039;t want the hassle of pictures in a DB... ANY DB that is!

  4. #4
    Join Date
    Dec 1969
    Posts
    2

    Default RE: I agree With Bill

    Thanks for the information - I&#039;ll change my approach and store strings with path statements instead of the binaries themselves...<BR><BR>J.<BR>


  5. #5
    Join Date
    Dec 1969
    Posts
    96,118

    Default MySQL makes it MORE of a pain...

    Read this:<BR><BR>*** QUOTE ***<BR>If you want to insert binary data into a string column (such as a BLOB), the following characters must be represented by escape sequences: <BR><BR>NUL <BR>ASCII 0. You should represent this by `&#039; (a backslash and an ASCII `0&#039; character). <BR> <BR>ASCII 92, backslash. Represent this by `\&#039;. <BR>&#039; <BR>ASCII 39, single quote. Represent this by `&#039;&#039;. <BR>" <BR>ASCII 34, double quote. Represent this by `\"&#039;. <BR>*** END QUOTE ***<BR><BR>That&#039;s from here:<BR> http://www.mysql.com/doc/en/String_syntax.html#IDX965<BR><BR>In other words, MySQL has no way to insert binary data except to convert the binary data to a string! (And in addition to all those characters, you probably need to escape the other characters--such as
    and --listed on that page.)<BR><BR>And all of this is made more problematical because VBScript has no way to take in binary data from the JPG file and convert it on a byte by byte basis in this manner. (Well, it could be done, but you&#039;d have to do one byte at a time. Not real practical for several 100KB images.)<BR><BR>You *PROBABLY* could do this using the ADODB.Stream object: You can create a Stream, load it up with the binary contents of a file, and then store the same Stream into a DB field.<BR><BR>As we said, it&#039;s a royal pain. And we haven&#039;t talked about getting the image *out* of the DB yet.<BR><BR>[I should note, though, that I&#039;m trying to build a universal scheme based on AppendChunk and GetChunk that *might* work. I still wouldn&#039;t recommend it, though.]<BR><BR>

Posting Permissions

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