Inserting images as BLOBs - any way to avoid using base64encode?
Terry Judd
tsj at unimelb.edu.au
Mon Aug 6 19:38:02 EDT 2007
Hi Jan - I'm already doing something along these lines except with the
base64encode/decode routines thrown in. Getting the image into the database
without encoding seems? to work ok but when I pull it out I can only get
hold of the first few characters, typically something like 'âPNG' and a
couple of returns.
Regards,
Terry...
> Hi Terry,
>
> You can try and use the "query with placeholder" style
> to push binary data into the database:
> ##
> put URL("binfile:" & tFilePath) into tBinaryData
> put "INSERT INTO images (:1, :2)" into tQuery
> revExecuteSQL gConnection, tQuery, "tFilePath", "*b" &
> tBinaryData
> put the result into tResult
> if char 1 to 8 of tResult is "revdberr" then
> answer error tResult
> else
> -- insert succeeded
> end if
> ##
>
> If the images are large, you'll want to use the
> revQueryDatabaseBLOB function to get the data out as a
> cursor. Then you can use the function
> 'revDatabaseColumnNamed' to extract the binary data.
> ##
> put "SELECT * FROM images" into tQuery
> put revDatabaseQueryBLOB(gConnection, tQuery) into
> tCursor
> if tCursor is not a number then
> answer error tCursor
> else
> put revDatabaseColumnNamed(tCursor,"binData") into
> tBinData
> -- do what you need to do
> -- ...
> -- clean up the cursor afterwards!
> revCloseCursor tCursor
> end if
> ##
>
> Base64Encoding is great if you have to move stuff
> accross platforms and technologies; but the above may
> do the trick for you.
>
> Hope this helped,
>
> Jan Schenkel.
>
--
Dr Terry Judd
Lecturer in Educational Technology (Design)
Biomedical Multimedia Unit
Faculty of Medicine, Dentistry & Health Sciences
The University of Melbourne
Parkville VIC 3052
AUSTRALIA
61-3 8344 0187
More information about the use-livecode
mailing list