0

I'm trying to create an app that lets the user upload an image to my server.

However it always return:

Error code 500 : Malformed Request

Maybe you have an idea what is wrong...

Here is the .lua code:

upload:addEventListener( "tap",
function( event )
if ( isPhoto == false ) then
    media.capturePhoto( { listener = onPhoto, destination = { baseDir = system.TemporaryDirectory, filename = "capture.jpg", type = "image" } } )
else
    local params = { timeout = 30, progress = true, bodyType = "binary" }
    local headers = {}
    headers.filename = filename
    params.headers = headers
    network.upload( "http://www.m7-studios.de/(link to .php)", "POST", onNetwork, params, "capture.jpg", system.TemporaryDirectory, "image/jpg" )
    end
    return true
end )

function onPhoto( event )
if ( event.completed == true ) then
    isPhoto = true
end

I'm using a example .php:

https://www.dropbox.com/s/yc3z9a9xgf5kkim/upload.php

Midhun MP
  • 103,496
  • 31
  • 153
  • 200

2 Answers2

0

I just read it very fast, but you get this error if you dont include the following parameters in youre request: HTTP_FILENAME CONTENT_TYPE CONTENT_LENGTH

this is written in this line in the php script:

if ((isset($_SERVER["HTTP_FILENAME"])) && (isset($_SERVER["CONTENT_TYPE"])) && (isset($_SERVER["CONTENT_LENGTH"])))

To send the parameters to your php script you need to add them to your params.body as a string, probably seperated by &:

params.body = "HTTP_FILENAME='filename'&CONTENT_TYPE='filetype'&CONTENT_LENGTH="..1024*1024*5

Not completly sure though, see the link I posted in the comments.

Dev Ze
  • 116
  • 6
  • Problem is, that I can't get image length in corona... However I deleted php image length check and tested it. doesnt work... :( –  Sep 24 '14 at 14:18
  • Sorry, I think I answered to fast. Reading [here](http://stackoverflow.com/questions/24112479/corona-sdk-lua-how-to-send-request-to-php-script-for-registering-a-device-to-g), You need to specify this values not in the headers variable but in the body variable ie. params.body="string with your variables, seperated with &". – Dev Ze Sep 25 '14 at 18:23
  • regarding the image size problem, see this [question](http://stackoverflow.com/questions/10712622/how-to-get-the-file-size-and-delete-file-in-lua) and the answer talking about the lua file system at the end. ps tell me if its working so I will update my first answer. – Dev Ze Sep 25 '14 at 18:25
  • Okay, got the problem. If I use system.DocumentsDirectory image get uploaded successfully. Problem is how to get this image to show up in my script? And why is it a problem to use TemporaryDirectory? –  Sep 25 '14 at 21:29
0

Solved. The mistake was the temporary saving of the image which seems to make problems.