Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upload file with multipart data #27

Open
thienhaole92 opened this issue Jan 29, 2016 · 2 comments
Open

upload file with multipart data #27

thienhaole92 opened this issue Jan 29, 2016 · 2 comments

Comments

@thienhaole92
Copy link

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
Copy link

Please show your code in Objective-C.

@thienhaole92
Copy link
Author

i wrote my code in LUA

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants