Hi friends,
I’m trying to upload a photo taken with the device camera to a remote server. I’m using the “How To - Upload an Image to a server (multipart/form-data)” example that you can find here:
http://developer.coronalabs.com/code/how-upload-image-server-multipartform-data
So far, I was able to successfully upload a local image to the remote system. However I’m unsuccessfully when trying to use the camera output.
Here is the my code:
[lua] local sessionComplete = function(event)
local image = event.target
local MultipartFormData = require(“class_MultipartFormData”)
local multipart = MultipartFormData.new()
multipart:addFile(“myfile”, system.pathForFile(event.target), “image/jpeg”, “myfile.jpg”)
local params = {}
params.body = multipart:getBody() – Must call getBody() first!
params.headers = multipart:getHeaders() – Headers not valid until getBody() is called.
local function networkListener( event )
if ( event.isError ) then
print( “Network error!”)
else
print ( tostring( image ) … " RESPONSE: " … event.response )
end
end
network.request( “http://myserver.com/uploader64.php”, “POST”, networkListener, params)
end
local onButtonRelease = function( event )
if media.hasSource( media.Camera ) then
media.show( media.Camera, sessionComplete)
else
native.showAlert(“Corona”, “Camera not found.”)
end
return true
end[/lua]
Now my doubt is on the following line of code:
[lua]multipart:addFile(“myfile”, system.pathForFile(event.target), “image/jpeg”, “myfile.jpg”)[/lua]
The part where I have system.pathForFile(event.target) is that correct? This code is sending a zero bytes file. I’ve only tried this with corona simulator.
Any help here is welcomed.
Thank you [import]uid: 189638 topic_id: 33231 reply_id: 333231[/import]
