DisplayObject to base64 is it possible?

Hi, im using media.selectPhoto() for a user to upload photos to a rest api using base64.

I create a temporay file pass that file to string(binary>string), encode to base64 in the process then send it to the server. the problem is media.selectPhoto() send to the listner when i select the photo too soon. what i mean is the photo is still not created  when media.selectPhoto jumps to the listner. i create a delay to correct this so this work with a delay. i don’t like this method, since the time of creating the image i can’t control and the delay, could fail.

My question is, if i remove this all steps of creating tempory files, i could pass direct object to binary>string>base64. is it possible?

if not, shouldn’t the listner on media.selectPhoto when a file is chosed in destiny, get called only after the file is created? i hate using timers.

regards,

Carlos.

noone knows if i can pass a display object direct to a string?

I’m not sure I follow what you mean by pass a display object to a string. That’s what base64 encoding does. You pass binary data in and you get a string object out. Binary can’t be represented as a string because it’s binary. The purpose of base64 encoding is to make something that can be used as a string from the binary data.

Rob

Rob, thx for your reply. i will try to explain better.

i made an object with display.newImageRect.

that object is in memory only, not in a file.

i want to pass that object to a base64 string so i can pass it though a rest api.

what i usually do, i need to pass that object to a file, then open it in binary then pass to base64 then close file then delete file. i was wondering if there is a easyway to do this passing directly an display.object>base64.

regards,

Carlos.

If you’re loading an image into a display.newImageRect(), then just use the file IO API’s to read the file in, not as a display object but a blob of data, base64 encode that blob. 

If you’re making a new image rect using various techniques, you would need to save that display object out as a file using display.save() and then read it back in with the file IO API’s and the base64 encode the blob.

Rob

the problem is exactly that. how to open an display.newImageRect() using IO API. remember i’m creating the image from media.selectPhoto(). i don’t have access to the original file.

i can’t just 

local fileHandle = io.open( filename, “rb” ). file name is an display.newImageRect() object.

your second option is already what i’m using. i’m hoping there are a better way than this, if corona can save an object to a binary file i should pass that same object to a base64string.

i need a a way that works like io.open but for objects in memory.

Carlos.

If it’s not a physical file you have access to, you will need to use one of the screen saving functions like display.save() to turn a display object into a physical file. Then you can open it and base64 encode it.

Rob

noone knows if i can pass a display object direct to a string?

I’m not sure I follow what you mean by pass a display object to a string. That’s what base64 encoding does. You pass binary data in and you get a string object out. Binary can’t be represented as a string because it’s binary. The purpose of base64 encoding is to make something that can be used as a string from the binary data.

Rob

Rob, thx for your reply. i will try to explain better.

i made an object with display.newImageRect.

that object is in memory only, not in a file.

i want to pass that object to a base64 string so i can pass it though a rest api.

what i usually do, i need to pass that object to a file, then open it in binary then pass to base64 then close file then delete file. i was wondering if there is a easyway to do this passing directly an display.object>base64.

regards,

Carlos.

If you’re loading an image into a display.newImageRect(), then just use the file IO API’s to read the file in, not as a display object but a blob of data, base64 encode that blob. 

If you’re making a new image rect using various techniques, you would need to save that display object out as a file using display.save() and then read it back in with the file IO API’s and the base64 encode the blob.

Rob

the problem is exactly that. how to open an display.newImageRect() using IO API. remember i’m creating the image from media.selectPhoto(). i don’t have access to the original file.

i can’t just 

local fileHandle = io.open( filename, “rb” ). file name is an display.newImageRect() object.

your second option is already what i’m using. i’m hoping there are a better way than this, if corona can save an object to a binary file i should pass that same object to a base64string.

i need a a way that works like io.open but for objects in memory.

Carlos.

If it’s not a physical file you have access to, you will need to use one of the screen saving functions like display.save() to turn a display object into a physical file. Then you can open it and base64 encode it.

Rob