Hey every people,
I’ve hit a snag trying to get the Corona library to upload files to my server. I have full control of the server, so I’m comfortable altering the code that saves the file from the post data, but my problem is that I seem to be getting empty post data (Whether it be from the $_POST, $_FILES or file_get_contents(“php://input”) raw post data).
Here’s a look at the code I’ve got so far.
– I open the phone’s gallery to allow the user to select a photo to be uploaded and saved into the temporary directory.
if media.hasSource( media.PhotoLibrary ) then
media.selectPhoto( {
mediaSource = media.PhotoLibrary,
listener = onComplete,
destination = {baseDir=system.TemporaryDirectory, filename=“image.jpg”, type=“image”}
} )
else
print_r(media)
--native.showAlert( “Corona”, “This device does not have a photo library.”, { “OK” } )
end
– I have this function defined earlier that processes the user’s response
function onComplete (event)
if ( event.completed ) then
network.upload(
"http://192.168.1.64/index/send-image",
“POST”,
networkListener,
{
bodyType = “binary”,
body = {test = “test”}
},
system.pathForFile( “image.jpg”, system.TemporaryDirectory ),
“image/jpg”
)
end
end
All this seems to work fine, I’m receiving a request from the server side, but the post data is empty.
In return for my eternal love and respect, can any one clue me on to where I’m going wrong?
Thanks,