Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Multipart Form Data
Started by apps30 Dec 17 2018 09:11 AM

2 replies to this topic
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

apps30

[GLOBAL: userInfoPane.html]
apps30
  • Enthusiast

  • 66 posts
  • Corona SDK

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.

 



[TOPIC: post.html]
#2

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,372 posts
  • Enterprise

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



[TOPIC: post.html]
#3

apps30

[GLOBAL: userInfoPane.html]
apps30
  • Enthusiast

  • 66 posts
  • Corona SDK

fields['Content-Type'] value is "image/jpeg".




[topic_controls]
[/topic_controls]