Is there a limit or something to the no of characters which can be input to the mime.b64 function?
The following (plug-n-play)code crashes the app in my iPhone…
[lua]local mime = require “mime”
local screenW = display.contentWidth
local screenH = display.contentHeight
local sW = screenW/2
local sH = screenH/2
local function convertDisplayObjectToBase64(image)
–save display object to a temp file
local fileName = “temp_custom.jpg”
local dir = system.TemporaryDirectory
display.save(image,fileName,dir)
–open and read file
local fileHandle = io.open( system.pathForFile( fileName ,dir), “rb” )
local imageData = fileHandle:read( “*a” )
fileHandle:close()
–base64 encode it
local encodedImageData = mime.b64(imageData)
return encodedImageData
end
local function imageListener(event)
local img = event.target
if not img then return end
img.width = screenW
img.height = screenH
img.x = sW
img.y = sH
timer.performWithDelay(2000,function()
local base64 = convertDisplayObjectToBase64(img)
print(base64)
end,1)
end
media.show(media.Camera, imageListener)[/lua]
What I am doing here is
- open camera and get an image
- scale and position the image
- after a delay of 2s call convertDisplayObjectToBase64 function
in the convertDisplayObjectToBase64 function
- save the image to a temporary file
- read the file to a variable
- base64 encode it using mime.b64
Now most of the times, the app crashes when the convertDisplayObjectToBase64 function is called… This happens only i the device. In the Mac Simulator, everything works fine…
Whats wrong here?
Does the crash occur because the file to be encoded is very large? [import]uid: 64174 topic_id: 33675 reply_id: 333675[/import]