I am using react and antd.
The component I am using from antd is Drag and Drop.
I am trying to send multipart/form-data using FormData object.
It sends the file (.zip file that should be sent as blob) but it does not send it as blob nor anything related to the other keys and values.
Here's a Sandbox.
Expected Request Payload:
------WebKitFormBoundaryysdTGvf0cRZVGpQ4
Content-Disposition: form-data; name="file"; filename="aFileName.zip"
Content-Type: application/octet-stream
[0,1,2]
------WebKitFormBoundaryysdTGvf0cRZVGpQ4
Content-Disposition: form-data; name="x2"
y2
------WebKitFormBoundaryysdTGvf0cRZVGpQ4
Content-Disposition: form-data; name="x3"
true
------WebKitFormBoundaryysdTGvf0cRZVGpQ4
Content-Disposition: form-data; name="x4"
2
------WebKitFormBoundaryysdTGvf0cRZVGpQ4
Actual Request Paylod:
------WebKitFormBoundaryysdTGvf0cRZVGpQ4
Content-Disposition: form-data; name="file"; filename="aFileName.zip"
Content-Type: application/zip
------WebKitFormBoundaryysdTGvf0cRZVGpQ4
I have used customRequest to solve this problem.
You can find an example here: Send multipart/form-data with antd upload #11616
If you just want to use <Upload> as a file input and only have <Form> submit the file for you, here is my solution
Related
I am trying to send an array as value for a hash key in a POST multipart request.
input = {"attribute"=> ["Countries:India", "Category:Can"]}
post("url")
.request_format_multipart_form.payload(input)
This works when using Ruby's HTTP and also POSTMAN. I can also see the differences between how Postman and Workato handles the form data.
Postman:
----------------------------428750340837882951989223
Content-Disposition: form-data; name="attribute"
Category:Test
----------------------------428750340837882951989223
Content-Disposition: form-data; name="attribute"
Countries:India
----------------------------428750340837882951989223--
Workato:
------RubyFormBoundaryhokO7A27Xb6cdSEz
Content-Disposition: form-data; name="attribute"; filename="attribute"
Content-Type: Category:Can
Countries:India
------RubyFormBoundaryhokO7A27Xb6cdSEz--
Why does Workato consider an array as a file? or am I wrong with the call?
I solved this by changing the request type to application/x-www-form-urlencoded and encode the input parameters as form data in the body (Using encode_www_form).
input = {"attribute"=> ["Countries:India", "Category:Can"]}
input = input.encode_www_form
post("url",input)
.request_format_www_form_urlencoded
I am currently trying to submit a request using the Swagger Inspector using multipart/form-data header to allow the submission of a file in conjunction with json data.
The JSON body of my request looks like:
And the headers with file upload look like:
For requests where I am just sending json to the server the Content-Type header is set to application/json and it is able to read from the body box. However I do not understand how this interface allows me to specify that the information coming from the body field is json and despite there being files on on the request.
I have seen requests that define multiple data types using the Conetent-Disspostion header, that look this this (reffenced from this Stack Overflow Post):
POST / HTTP/1.1
[[ Less interesting headers ... ]]
Content-Type: multipart/form-data; boundary=---------------------------735323031399963166993862150
Content-Length: 834
-----------------------------735323031399963166993862150
Content-Disposition: form-data; name="text1"
text default
-----------------------------735323031399963166993862150
Content-Disposition: form-data; name="text2"
aωb
-----------------------------735323031399963166993862150
Content-Disposition: form-data; name="file1"; filename="a.txt"
Content-Type: text/plain
Content of a.txt.
-----------------------------735323031399963166993862150
Content-Disposition: form-data; name="file2"; filename="a.html"
Content-Type: text/html
<!DOCTYPE html><title>Content of a.html.</title>
-----------------------------735323031399963166993862150
Content-Disposition: form-data; name="file3"; filename="binary"
Content-Type: application/octet-stream
aωb
-----------------------------735323031399963166993862150--
My question would be how do I create a request in swagger inspector that accepts multiple data types? It seems like I would need to set mulple sections in the body separated by boundaries with multiple Content-Disposition and Content-Type's for each. Would there be a cleaner way to do that through the Swagger Inspector interface? Or am I going about this in the wrong way?
Thanks!
Swagger Inspector currently supports multipart/form-data requests containing one or more files. It does not support arbitrary body parts in multipart requests (e.g. a file + JSON or text data). You'll need to use another HTTP client to test such requests.
You can submit feature request for Swagger Inspector here:
https://community.smartbear.com/t5/Swagger-Inspector-Feature/idb-p/SwaggerInspectorFeatureRequests
I'm facing an issue trying to send multiples files from a ReactJS App to a Symfony Backend.
I upload two files but only one is visible in my Symfony backend.
Data are sent from a ReactJS dropzone, I well checked that the two files are sent via formData, I well used the 'content-type': 'multipart/form-data' to post the data.
In Chrome Newtwork Tab, the Form Data details shows that two files are well attached to the request :
------WebKitFormBoundaryTif9sihCtI30UXXS Content-Disposition: form-data; name="file"; filename="glacier-583419_960_720.jpg"
Content-Type: image/jpeg
------WebKitFormBoundaryTif9sihCtI30UXXS Content-Disposition: form-data; name="file"; filename="image-ile.jpg" Content-Type:
image/jpeg
Nevertheless, in my Symfony backend the File Parameter Bag only shows one file :
return $request->files;
Serialized response :
{
"parameters": {
"file": {
"test": false,
"original_name": "glacier-583419_960_720.jpg",
"mime_type": "image/jpeg",
"error": 0
}
},
"file_keys": [
"error",
"name",
"size",
"tmp_name",
"type"
]
}
As you can see, in "parameters", only one file is present instead of two.
Is anybody already encountered this problem ? I don't have any idea of what could be the issue ?
I solved my issue, it was trivial but it could help someone else for future readings.
As per indicated in the Form Data sent :
------WebKitFormBoundaryTif9sihCtI30UXXS Content-Disposition: form-data; name="file"; filename="glacier-583419_960_720.jpg" Content-Type: image/jpeg
------WebKitFormBoundaryTif9sihCtI30UXXS Content-Disposition: form-data; name="file"; filename="image-ile.jpg" Content-Type: image/jpeg
Each element added in the Form Data had the same name value.
Here is the problem :
var tempFormData = new FormData();
setFormData(acceptedFiles.map((file)=>{
tempFormData.append('file', file);
}));
Corrected code :
var tempFormData = new FormData();
setFormData(acceptedFiles.map((file)=>{
tempFormData.append(file.name, file);
}));
So the error was not coming from Symfony but from front-end App not well formatting the data sent.
We are using Redemption from an Outlook addin for save messages to EML format (RFC822).
There was an unfortunate situation when one of out customer attached several EML file attachments into her email (and these emails were saved with Redemption).
The generated EML is not the same if I open in Outlook like the original message.
IMHO the issue caused by the fact the attached EML files using the same "00B0FEED_message_boundary" ID for message part boundaries.
I try to explain below:
... headers ..
Content-type: Multipart/mixed; charset=iso-8859-1;
boundary="00B0FEED_message_boundary"
Content-Description: Multipart message
--00B0FEED_message_boundary
Content-type: Multipart/alternative; charset=ISO-8859-1;
boundary="00B0FEEE_message_boundary"
Content-Description: Multipart message
--00B0FEEE_message_boundary
Content-type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Content-Description: Message text
... message body in plain text format ...
--00B0FEEE_message_boundary
Content-type: text/html; charset=iso-8859-1
Content-Transfer-Encoding: Quoted-printable
Content-Disposition: inline
Content-Description: HTML text
... message body in HTML format ...
--00B0FEEE_message_boundary--
--00B0FEED_message_boundary
Content-type: application/octet-stream; charset=iso-8859-1;
name="=?iso-8859-1?Q?1=20Ab-=20und=20Zuschl=E4ge=2EEML?="
Content-Transfer-Encoding: Quoted-printable
Content-Disposition: attachment;
filename="=?iso-8859-1?Q?1=20Ab-=20und=20Zuschl=E4ge=2EEML?="
Content-Description: =?iso-8859-1?Q?1=20Ab-=20und=20Zuschl=E4ge=2EEML?=
... first attached message headers ...
Content-type: Multipart/mixed; charset=3Dutf-8;
boundary=3D"00B0FEED_message_boundary" <------ inner message boundary ID
Content-Description: Multipart message
--00B0FEED_message_boundary
Content-type: Multipart/related; charset=3DISO-8859-1;
boundary=3D"00B0FEEE_message_boundary"
Content-Description: Multipart message
--00B0FEEE_message_boundary
Content-type: Multipart/alternative; charset=3DISO-8859-1;
boundary=3D"00B0FEEF_message_boundary"
Content-Description: Multipart message
--00B0FEEF_message_boundary
Content-type: text/plain; charset=3Dutf-8
Content-Transfer-Encoding: Quoted-printable
Content-Disposition: inline
Content-Description: Message text
... first attached message body in plain text ...
--00B0FEEF_message_boundary
Content-type: text/html; charset=3Dutf-8
Content-Transfer-Encoding: Quoted-printable
Content-Disposition: inline
Content-Description: HTML text
... first attached message body in HTML ...
--00B0FEEF_message_boundary--
--00B0FEED_message_boundary--
--00B0FEED_message_boundary
... several other similar EML messages
This message not opening correctly in Outlook, but if I change the inner message boundary ID (and modify the corresponding part in the inner message) the EML opening correctly. So I presume this similar ID the cause of my issue.
Is there any workaround to force to use random ID for message boundary? Maybe to force to BASE64 encode the attachments?
I am writing an app that decrypts encrypted emails for a client.
The encrypted data is in the form of an email attachment, which, when decrypted, looks like this :
Content-Type: multipart/mixed;
boundary="PGP_Universal_830ECF7A_AFB087B4_241DE401_9BE7FFD1"
--PGP_Universal_830ECF7A_AFB087B4_241DE401_9BE7FFD1
Content-Type: multipart/alternative;
boundary="PGP_Universal_904F5C3F_3A8C9E07_A3A24D11_F0FB260C"
--PGP_Universal_904F5C3F_3A8C9E07_A3A24D11_F0FB260C
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7BIT
[snip]
--PGP_Universal_904F5C3F_3A8C9E07_A3A24D11_F0FB260C
Content-Type: text/html;
charset=us-ascii
Content-Transfer-Encoding: QUOTED-PRINTABLE
[html content]
--PGP_Universal_904F5C3F_3A8C9E07_A3A24D11_F0FB260C--
--PGP_Universal_830ECF7A_AFB087B4_241DE401_9BE7FFD1
Content-Type: application/pdf;
name="BB_FW_60_Manual_Key.Enrollment_Final_v1.pdf"
Content-Transfer-Encoding: BASE64
Content-Disposition: attachment;
filename="BB_FW_60_Manual_Key.Enrollment_Final_v1.pdf"
[base64 data]
--PGP_Universal_830ECF7A_AFB087B4_241DE401_9BE7FFD1--
I am writing the app in Cascades. As I cannot find a native way of transforming this data into an email, to let the email client deal with the attached base64-encoded file and so on, I am hoping to find a C++ class (it can optionally depend upon Qt, obviously) that I can use on the BB10 which can parse these kind of multipart messages.
It is possible to get SPMIME to compile on BB10. It is LGPL so it might need to be compiled seperately and linked to if your app is not GPL.