Page 1 of 1
base64encode an image hanging?
Posted: Tue May 12, 2015 12:50 am
by Gazzafish
I am trying to base64encode an image on android. i plan to then transfer it as text to my mysql database on my hosting account (as a blob). Problem is, when i execute the script on my samsung s4 phone, the base64encode step appears to take forever and eventually my phone reports that my application is not responding. I am not sure how long it takes to encode an image file taken from the phones camera (8mp i think). I have an image called "thumbnail" and i manage to put the photo into image thumbnail fine. My command to base64encode this image is :-
put base64encode (image thumbnail) into image_base64
I was hoping that my variable "image_base64" would contain the encoded text but i never get that far..
Any thoughts? And would anyone have a guess as to how long a phone would take to do this process?
thanks in advance.
Re: base64encode an image hanging?
Posted: Mon May 18, 2015 10:47 am
by MaxV
If all will work inside a livecode program, use this:
Code: Select all
put the text of image "thumbnail" into temp
put base64encode(temp) into image_base64
Let me know
Re: base64encode an image hanging?
Posted: Tue May 19, 2015 9:36 am
by Gazzafish
THAT WORKS!!! Thanks you so very much.

Re: base64encode an image hanging?
Posted: Tue May 19, 2015 9:55 am
by MaxV
Ok,

remember that
the text contains only the informations on pixels, but not the size an image. For example an image made of 16 pixels may be 4x4, 8x2 or 16x1. So you have to store in another variable the size (width and height).
Re: base64encode an image hanging?
Posted: Tue May 19, 2015 10:01 am
by MaxV
However you probably don't need to use base64encode, you could send binary data directly to your database:
From
http://livecode.wikia.com/wiki/SQLite :
Working with binaries
In order to upload binaries, you need to use the variable in the
revExecuteSQL.
The SQLStatement may contain one or more placeholders, which are sequential numbers prepended by a colon. The revExecuteSQL command substitutes the corresponding item in the variablesList for each of these placeholders. For example, if you have two variables called "valueX" and "valueY", you can use a SQLStatement that includes placeholders as follows:
Code: Select all
revExecuteSQL myID, "insert into mytable values(:1,:2)", "valueX","valueY"
when using binaries, you have to insert the
*b prefix in variable name; so if you variable containing a binary is "valueX", the correct code is:
Code: Select all
revExecuteSQL myID, "insert into mytable values(:1)", "*bvalueX"
Since the revExecuteSQL command strips the binary marker "*b" and passes it to the database as binary data, rather than text data.
Example with UPDATE:
Code: Select all
put "UPDATE flags SET logo=:1 WHERE ID="& tID &" ;" into tSQL
revExecuteSQL connID,tSQL,"*blogo"