Hello. I can uploaded base64 encoded image files to the Parse backend with code looking something like this:
[lua] local filename = “image.jpg”
local path = system.pathForFile( filename )
local fileHandle = io.open( path, “rb” )
local b64 = mime.b64( fileHandle:read( “*a” ) )
local params = {}
params.headers = headers
params.body = ‘{ “image”: { “__type”: “Bytes”, “base64”: "’…b64…’"} }’
local function networkListener( event )
if ( event.isError ) then
print( “Network error!”)
else
print ( "RESPONSE: " … event.response )
end
io.close( fileHandle )
end
network.request( parseUrl, “POST”, networkListener, params)[/lua]
But when I download the image to my app again with this code:
[lua] local function networkListener( event )
if ( event.isError ) then
print( “Network error!”)
else
local response = json.decode( event.response )
local unb64 = mime.unb64(response[“image”][“base64”])
local path = system.pathForFile( filename, system.DocumentsDirectory )
local file = io.open( path, “w+b” )
file:write( unb64 )
file:close()
end
end
network.request( parseUrl, “GET”, networkListener, params)[/lua]
The image file is corrupted somehow.
Did anyone try to do anythingg similar? Any suggestions?
Thanks!
[import]uid: 13632 topic_id: 20688 reply_id: 320688[/import]