Multipart Form Data

Hi, I am trying to submit a “multipart/form-data” using this:

https://raw.githubusercontent.com/benglard/Augment/master/App/class_MultipartFormData.lua

I did get response from the server but the image file seems not able to upload or something wrong. When I tried to download my uploaded image, it shows a blank image only.

The following is my code:

local MultipartFormData = require("class\_MultipartFormData") local multipart = MultipartFormData.new() multipart:addHeader("Content-Type", "multipart/form-data") multipart:addField("acl",fields['acl']) multipart:addField("Content-Type",fields['Content-Type']) multipart:addField("key",fields['key']) multipart:addField("AWSAccessKeyId",fields['AWSAccessKeyId']) multipart:addField("policy",fields['policy']) multipart:addField("signature",fields['signature']) multipart:addFile("file", system.pathForFile( "profile\_pic.jpg", system.TemporaryDirectory ), fields['Content-Type'], "profile\_pic.jpg") local params = {} params.body = multipart:getBody() params.headers = multipart:getHeaders() network.request( baseUrl, "POST", networkListener, params)

Anyone can help? I don’t have any control on the server side. I need to upload an image file in temp folder with some fields data for validation with the given API call.

While we can’t provide support for this third-party feature, your Content-Type’s don’t look right. It should be something like “image/jpeg”.  See:

https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Complete_list_of_MIME_types

The example in the module shows:

multipart:addFile("myfile", system.pathForFile( "myfile.jpg", system.DocumentsDirectory ), "image/jpeg", "myfile.jpg")

I’m not sure in your fields[‘Content-Type’] has in it.

Rob

fields[‘Content-Type’] value is “image/jpeg”.

While we can’t provide support for this third-party feature, your Content-Type’s don’t look right. It should be something like “image/jpeg”.  See:

https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Complete_list_of_MIME_types

The example in the module shows:

multipart:addFile("myfile", system.pathForFile( "myfile.jpg", system.DocumentsDirectory ), "image/jpeg", "myfile.jpg")

I’m not sure in your fields[‘Content-Type’] has in it.

Rob

fields[‘Content-Type’] value is “image/jpeg”.