Hello everyone,
I’ve been working on an app where people will be able to upload images to a PHP script on my server. I’m using the multipart form script by bpappin. I have scoured the forums for an answer to this, my code comment points out what I can’t figure out:
[lua]local MultipartFormData = require(“class_MultipartFormData”)
local function onTap()
local onComplete = function(event)
local photo = event.target
local multipart = MultipartFormData.new()
multipart:addField(“imagetitle”,“testing from app”)
multipart:addField(“tags”,“a test, testing, the testing tag”)
multipart:addField(“category”,“Funny”)
multipart:addField(“sortorder”,“1”)
–Below is where I’m going wrong, how do I put the selected photo object into the POST statement? The other data seems to be posting fine.
multipart:addFile(“photo”, system.pathForFile( photo, system.DocumentsDirectory ), “image/jpeg”, “userupload.jpg”)
local params = {}
params.body = multipart:getBody()
params.headers = multipart:getHeaders()
local function networkListener( event )
if ( event.isError ) then
print( “Network error!”)
else
local decoded_response = json.decode(event.response)
if (decoded_response.theanswer == 1) then
– do stuff
end
if (decoded_response.theanswer == 0) then
– do stuff
end
end
end
network.request(“http://www.mywebsite.com/imageprocessor.php”, “POST”, networkListener, params )
end
media.show( media.PhotoLibrary, onComplete )
end
mybutton:addEventListener(“tap”, onTap)[/lua]
I appreciate any insight, thanks in advance if you can help! [import]uid: 119161 topic_id: 25373 reply_id: 325373[/import]