I am trying this to send a picture to my web server but it doesn´t work:
function uploadBinary ( filename, url, onComplete ) {
local mime = require "mime"
local path = system.pathForFile( filename )
local fileHandle = io.open( path, "rb" )
if fileHandle then
local params = {
headers = {["Content-Type"] = "multipart/text"},
body = mime.b64( fileHandle:read( "\*a" ) ),
}
io.close( fileHandle )
local function networkListener ( event )
-- Note: event.isError and event.response can tell
-- your onComplete function how it went.
if (onComplete) then
onComplete(event);
end
return true;
end
network.request( url, "POST", networkListener, params)
end
end
-- uploadBinary ( filenameToUpload, postToUrl [, onComplete])
uploadBinary ( "myScreenshot.png", "http://mywebpage.com/receiveBinary.php")
The php-file looks like this:
<?php# This script receives a binary file uploaded from a Corona # app. If you are uploading something other than a PNG, # you will want to change that here: $filename = "myFile-" . time() . ".png"; $pngdata = $HTTP\_RAW\_POST\_DATA; if( isset( $pngdata ) ) { $img\_file = fopen ($filename, 'wb'); fwrite ($img\_file, base64\_decode( $pngdata )); fclose ($img\_file); echo "Success."; } else { echo "Failure."; } ?\> I get an error message saying: main.lua:4: unexpected symbol near '{' Anybody who can help me with this? [import]uid: 5717 topic\_id: 16613 reply\_id: 316613[/import]