alibaba/wax

upload file with multipart data

thienhaole92 opened this issue · 2 comments

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

Please show your code in Objective-C.

i wrote my code in LUA