upload binary (multipart/form-data)

Hey everyone!

I’m trying to upload an image with an string to my web site through php

the code works fine in simulator, I can upload my image BUT I can’t open image after uploaded and in device I can’t upload I get an error:

“Lua Runtime Error: lua+pcall failed with status: 2, error message is: assertion failed!”

someone can please help me?

The code for this:

local MultipartFormData = require("class\_MultipartFormData")  
   
local multipart = MultipartFormData.new()  
multipart:addHeader("Customer-Header", "Custom Header Value")  
multipart:addField("myFieldName","myFieldValue")  
multipart:addField("banana","yellow")  
multipart:addFile("myfile", system.pathForFile( "myfile.jpg", system.DocumentsDirectory ), "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 ( "RESPONSE: " .. event.response )  
 end  
end  
   
network.request( "http://www.example.com", "POST", networkListener, params)  
$myparam = $\_POST['myFieldName'];  
echo $myparam;  
   
$target\_path = "uploads/";  
   
$target\_path = $target\_path . basename( $\_FILES['myfile']['name']);   
   
if(move\_uploaded\_file($\_FILES['myfile']['tmp\_name'], $target\_path)) {  
 echo "The file ". basename( $\_FILES['myfile']['name']).   
 " has been uploaded";  
} else{  
 echo "There was an error uploading the file, please try again!";  
}  

[import]uid: 23063 topic_id: 18361 reply_id: 318361[/import]

are you sure you add permission to access internet in your config file ??? [import]uid: 74537 topic_id: 18361 reply_id: 70383[/import]

I need to in iPad/iPhone? [import]uid: 23063 topic_id: 18361 reply_id: 70384[/import]

i cant understand what you mean in iphone is it work in android devices ?
[import]uid: 74537 topic_id: 18361 reply_id: 70387[/import]

I only tested in iPad [import]uid: 23063 topic_id: 18361 reply_id: 70390[/import]

Dhennrich, if you can post a sample project download someone may be able to further assist you. (Or plug and play.)

mhantash - I have already asked you once not to hijack threads. Copying and pasting the same thing into multiple threads where it is NOT relevant at all is going to get you in trouble - so don’t do it. http://developer.anscamobile.com/forum/2011/05/05/forum-rules-and-guidelines

Peach :slight_smile: [import]uid: 52491 topic_id: 18361 reply_id: 70513[/import]

??? [import]uid: 74537 topic_id: 18361 reply_id: 70392[/import]