base64encode an image hanging?

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
Gazzafish
Posts: 16
Joined: Tue Aug 12, 2014 4:16 am

base64encode an image hanging?

Post by Gazzafish » Tue May 12, 2015 12:50 am

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.

MaxV
Posts: 1580
Joined: Tue May 28, 2013 2:20 pm
Contact:

Re: base64encode an image hanging?

Post by MaxV » Mon May 18, 2015 10:47 am

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
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

Gazzafish
Posts: 16
Joined: Tue Aug 12, 2014 4:16 am

Re: base64encode an image hanging?

Post by Gazzafish » Tue May 19, 2015 9:36 am

THAT WORKS!!! Thanks you so very much. :D

MaxV
Posts: 1580
Joined: Tue May 28, 2013 2:20 pm
Contact:

Re: base64encode an image hanging?

Post by MaxV » Tue May 19, 2015 9:55 am

Ok, :D 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).
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

MaxV
Posts: 1580
Joined: Tue May 28, 2013 2:20 pm
Contact:

Re: base64encode an image hanging?

Post by MaxV » Tue May 19, 2015 10:01 am

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"
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

Post Reply