OTRS POST Boundary Generation - post

I am trying to CURL tickets/mails with the OTRS software.
The POST request contains of multiple lines like:
-----------------------------21268931210424524295626371432
Content-Disposition: form-data; name="ChallengeToken"
>random-token<
-----------------------------21268931210424524295626371432
Content-Disposition: form-data; name="Action"
AgentTicketEmail
Furthermore the header contains:
Content-Type: multipart/form-data; boundary=---------------------------21268931210424524295626371432
However using a random boundary is not working at all and the server returns an error 500. Does anybody know, how this boundary is generated and validated?

Related

How to post an image with form-data in Rest Client for VSCode

The documentation for the VSCode Rest Client is lacking good explinations. Here is what they give as an example.
POST https://api.example.com/user/upload
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="text"
title
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="image"; filename="1.png"
Content-Type: image/png
< ./1.png
------WebKitFormBoundary7MA4YWxkTrZu0gW--
Not sure what the < is for nor the title?
For the boundary part, I recomend read this post.
< It´s a symbol to indicate input stream, the file you want to send needs to be in the same directory as the .rest file that the restclient extension uses.
Quick response: boundary is to define where each pair of fields passed in the form is begins and ends. In your example there are two form fields, text="title" and image=1.png the bytes image sequence.
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="image"; filename="1.png"
Content-Type: image/png
< ./1.png
------WebKitFormBoundary7MA4YWxkTrZu0gW--
Other data such as filename="1.png" or Content-Type: image/png indicate additional information that the form loads by default when you select an image with a file type input.
Another example for a field description.
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="description"
All text of description.
------WebKitFormBoundary7MA4YWxkTrZu0gW
this 👇 "Rest Client" snippet works for me (solution from here).
*Note the boundry=MfnBoundry does not use a delimiter, while --MfnBoundry is used to open it, and --MfnBoundry-- is used to close it.
POST http://localhost:3000/api/upload HTTP/1.1
Content-Type: multipart/form-data; boundary=MfnBoundry
--MfnBoundry
Content-Disposition: form-data; name="files"; filename="test.txt"
Content-Type: text/plain
< ./test.txt
--MfnBoundry--

unable to post multipart/form-data to an endpoint using wmMediator

I encountered a problem with Mediator (9.7 with Fix 11) package, and I would like to know if you have encountered the same thing or if you have some ideas to correct or get around it ?
The problem is : I have a http REST-like request, which is in fact a multipart/form-data page. When I call it by Mediator (virtualized with Centrasite), the multipart payload is transformed in xml format. The endpoint is not able to respond correctly with that format.
Why mediator do this transformation and how can we prevent it ?
In Mediator input, we have this :
Content-Type: multipart/form-data; boundary=---- WebKitFormBoundaryiBMdnONIEM1rPnWp\r\n
------WebKitFormBoundaryiBMdnONIEM1rPnWp
Content-Disposition: form-data; name="typeEnvoi"
99
------WebKitFormBoundaryiBMdnONIEM1rPnWp
Content-Disposition: form-data; name="prenom"
hhhh
------WebKitFormBoundaryiBMdnONIEM1rPnWp
Content-Disposition: form-data; name="fileVisualExam1"; filename="Mezer_Stamp.png"
Content-Type: image/png
?PNG
The endpoint recieve that :
Content-Type: application/xml; charset=UTF-8
<?xml version='1.0' encoding='UTF-8'?><tns:POST_AppMobile
xmlns:tns="http://namespaces.compagny.com/wsdl">
<typeEnvoi>99</typeEnvoi>
<fileVisualExam1>iVBORw0KGgoAAAANSUhEUgAAAF4AAABZCAYAAAC315PWAAAAAXNSR0IArs
4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAARZSURBVHja7NAJAQAwEAIg+5
[...] Wp70lgEAafIxtwjUN/HS1B12VkNYiYm0i9wcjG1+yo+S9ZjauIsIDRm5RobKkeQoQ2fYxx9DUmU5S9Kx
T8QwYfynJcRoSFgt6mVKqxBdehf4bx9B7G0A+Y6r6ra9R1VdvI=</fileVisualExam1>
<prenom>hhhh</prenom></tns:POST_AppMobile>
I have made some attemps by modifying the content-types.xml config file for mediator (adding multipart or binary for that mime), but without success.
Please install the latest Mediator 9.7 Fix (currently fix 18). As of Fix 15, the following issue has been resolved:
SMGME-5868 (Fix 15)
Mediator transforms rest request of type multipart/form-data to XML.
When requests with multipart/form-data are sent to Mediator, Mediator converts
the request to application/xml. This issue is resolved
This should resolve your issue.

Asana Rest Api - Upload Attachment not loading image

I'm having some trouble uploading an image to an asana task. I get a 200 on the response but when I navigate to the image it is not loading and appears broken.
Here is what my request header looks like:
https://app.asana.com/api/1.0/tasks/<TaskId>/attachments - Http Post
Authorization: Bearer <o-auth token>
Content-Type: multipart/form-data; boundary=ASANA_BOUNDARY
Host: app.asana.com
Accept: */*
Content-Length: 1457324
Fiddler-Encoding: UTF8
Here is what the body of my request looks like:
--ASANA_BOUNDARY
Content-Disposition: form-data; name="file"; filename="koala.jpg"
Content-Type: image/jpeg
<Raw Data>
--ASANA_BOUNDARY--
I'm not really sure why this is giving me a 200 and then no image loads. I formed my request as noted in the documentation.

Post JPEG file using fiddler with other body data

I'm trying to post a jpeg file to a locally developed web service via Fiddler. This would be simple enough, but I also need to include some data alongside the file and can’t quite nail the syntax that fiddler wants. If I click the upload file button and select a file to upload, it replaces my POST body with:
---------------------------acebdf13572468
Content-Disposition: form-data; name="fieldNameHere"; filename="PantheraLeo.jpg"
Content-Type: image/jpeg
<#INCLUDE *C:\temp\PantheraLeo.jpg*#>
---------------------------acebdf13572468—
Now I want to add some additional data:
user=1&album=2&photo=[OUTPUT FROM FILE UPLOAD]
I’ve tried putting this at the start of the body, but when my Node app receives the request, I’m getting a user parameter, an album parameter but no photo.
Any ideas on how I could format this request to get both parameters and the photo uploaded as the photo parameter?
I've also been looking to do something similar myself and stumbled on your question. I've just managed to achieve what I needed after a bit of messing about with Fiddler. Try this:
---------------------------acebdf13572468
Content-Disposition: form-data; name="model"
MyModelInfo
---------------------------acebdf13572468
Content-Disposition: form-data; model="test123"; filename="123.gif"
Content-Type: image/gif
<#INCLUDE *Z:\Downloads\123.gif*#>
---------------------------acebdf13572468--
It would seem that you link the form data being sent up in your request body to the 'acebdf13572468' boundary in the POST info. Provide the Content-Disposition with a key name (in my case 'model') and then the following line represents your actual value for this key. (In my case "MyModelInfo".
Using the above request body I was able to POST up a file as well as some accompanying POST data to my API.
The accepted answer works well. But be warned the extra line after MyModelInfo comes through into the string. Also when copying and pasting in and out of fiddler some lines were corrupted breaking the file.
Note I have named the file param "file" in the fiddler body and in the receiving API function.
This works for me:
---------------------------acebdf13572468
Content-Disposition: form-data; name="PARAM1"
Some text with a line before but not after
---------------------------acebdf13572468
Content-Disposition: form-data; name="file"; filename="filename.jpg"
Content-Type: image/jpeg
<#INCLUDE *C:\local\filename.jpg*#>
---------------------------acebdf13572468--
The data can be received in .net core 2 like this:
[HttpPost]
[Route("AddImage")]
public async System.Threading.Tasks.Task<IActionResult> AddImageAsync(IFormFile file)
{
//f is the same as file
//var f = Request.Form.Files.Count > 0 ? Request.Form.Files[0] : null;
//useful to check the keys
//var additionalProperties = Request.Form.Keys;
if (file != null)
{
try
{
if (Request.Form.TryGetValue("PARAM1", out StringValues p1))
{
var txt = p1.ToString():

Apache benchmark multipart/form-data

i'm facing a strange problem with apache benchmark post file.
I need to stress a feature that handles file upload. So, I googled about, and found a post describing how to build a post file properly. Its contents looks like:
--1234567
Content-Disposition: form-data; name="user_id"
3
--1234567
Content-Disposition: form-data; name="file"; filename="cf_login.png"
Content-Type: image/png
[base64 encoded file content]
--1234567--
The ab line is this:
$ ab -c 1 -n 5 -v 4 -T 'multipart/form-data; boundary=1234567' -p post_file.txt http://localhost:3000/files
When ab make the requests the generated header is the following:
INFO: POST header ==
---
POST /files.json/ HTTP/1.0
Content-length: 229
Content-type: multipart/form-data; boundary=simpleboundary
Host: localhost:3000
User-Agent: ApacheBench/2.3
Accept: */*
---
LOG: header received:
HTTP/1.1 500 Internal Server Error
Content-Type: text/html; charset=utf-8
Content-Length: 13265
X-Request-Id: 9ad57d19cd71886a1bb817d00fac651b
X-Runtime: 0.015504
Server: WEBrick/1.3.1 (Ruby/1.9.3/2012-04-20)
Date: Tue, 25 Sep 2012 13:54:29 GMT
Connection: close
The expected return is a raise params.inspect, that let me see if the data is arriving to the other side. If I remove the boundary I can see data received in params, but this is not what I want. I want to get a file upload.
Anyone has a tip? I will really appreciate it.
I found the answer, and decided to share with you.
After some struggle with the post file, I decided to create a php script just to output the $_FILES and $_REQUEST variables to see if the file was built correctly. Indeed, apache receive the file perfectly and I could see the file data, and other request params.
With Rails the same doesn't occur, and after reading the documentation of HTTP 1.1 multipart topic, I realize that the problem was related to the post file format.
When you built this kind of file, you need to build it in details, and this means include all the special characters like \r and \n in the right place. The multipart does now work with "\n" at all, it needs "dos" line ending "\r\n".
So the correct post file looks like this (the \r\n is for illustration, but should be there, you know?):
--boundary_hash\r\n
Content-Disposition: form-data; name="your_form_field";\r\n
Content-Type: text/plain\r\n
\r\n
your form field data\r\n
--boundary_hash\r\n
Content-Disposition: form-data; name="another_field";\r\n
Content-Type: text/plain\r\n
\r\n
another field data\r\n
--boundary_hash\r\n
Content-Disposition: form-data; name="filename"; filename="cf_login.png"\r\n
Content-Type: image/png\r\n
\r\n
base64 file content\r\n
--boundary_hash--\r\n
When you open this file you see this actually:
--boundary_hash
Content-Disposition: form-data; name="your_form_field";
Content-Type: text/plain
your form field data
--boundary_hash
Content-Disposition: form-data; name="another_field";
Content-Type: text/plain
another field data
--boundary_hash
Content-Disposition: form-data; name="filename"; filename="cf_login.png"
Content-Type: image/png
base64 file content
--boundary_hash--
I hope that helps you.
Cheers.

Resources