Loading images to MySQL using Read/Write

Jim Schaubeck schaubeck at mac.com
Mon Feb 26 01:28:00 EST 2007


The Read/Write and URL commands are driving me sort of nuts.  I am trying to store image files into MySQL fields without using the imageData (which gets very large but I got it working).  Instead, I thought of reading the original image file, store that read into the MySQL field.  When I retrieve it, I would write it to a temp file x and set the empty image to the filename of x.  Sounded simple enough (too simple I guess).  Here's the test stack I was trying prove the theory with:


on mouseup
  ask file "Select an Image file"
  put it into tempvar
  --
  open file tempvar for binary read
  read from file tempvar until end
  put it into imagevar -- I'm hoping imagevar this would have the data I need to store in MySQL
  close file tempvar
  --
  open file "tempImageFile" for write
  write imagevar to file "tempImageFile" at 1
  close file "tempImageFile"
  --
  set the fileName of image "image1" to "tempImageFile"
end mouseUp


I know I could have set the fileName of the image to the origianl ask file result but I wanted to do the read/Write to see if I could duplicate the file contents and load it into another file and use the new file as the fileName.  That would prove out the theory (I think).  Does the Read/Write commands do a 1 for 1 read/write?

If read/write is not the way to go, any other ideas on how to store Jpegs to a MySQL field?

Thanks for your help,
Jim...



More information about the use-livecode mailing list