alibaba / wax

Wax is a framework that lets you write native iPhone apps in Lua.
http://github.com/probablycorey/wax
MIT License
1.84k stars 280 forks source link

upload file with multipart data #27

Open thienhaole92 opened 8 years ago

thienhaole92 commented 8 years ago

I want to upload an image to server. How can I set image to url?

function HTTPMultipartBeginMethod(url, fileData, completionHandler) puts ('HTTPMultipartBeginMethod') print ('request url: '..url) local requestcallback = function(body, response) if response == nil then HTTPFailureProcessing(0, nil, completionHandler) else local statusCode = response:statusCode() if statusCode == 200 then print 'request successed' HTTPSuccessProcessing(statusCode, body, completionHandler) else print 'request failure' HTTPFailureProcessing(statusCode, body, completionHandler) end end end local base64 = require 'Base64' local avatar = base64.enc(fileData)

local requestheaders = {}
requestheaders['Content-Type'] = 'multipart/form-data; boundary=0xKhTmLbOuNdArY'
local requestbody = [[
--0xKhTmLbOuNdArY
Content-Disposition: form-data; name="submit-name"
Larry
--0xKhTmLbOuNdArY
Content-Disposition: form-data; name="avatar"; filename="image.png"
Content-Type: application/octet-stream
... contents of image.png ...
hello
--0xKhTmLbOuNdArY--]]
puts (requestbody)

wax.http.request{ url, headers = requestheaders, body = requestbody, callback = requestcallback}

end

majie1993 commented 8 years ago

Please show your code in Objective-C.

thienhaole92 commented 8 years ago

i wrote my code in LUA