I´m trying to get a file upload to my JAX-RS controller working with multipart. I´ve been using the integrated REST HTTP Client of IntelliJ, that is recommending me to switch to the new HTTP Client by using .http files.
However, once I´m doing that I´m unable to do any uploads and I´m running into this exception
exception
java.io.IOException: RESTEASY007550: Unable to get boundary for multipart
request.http
POST http://localhost:8080/content/upload
Accept: */*
Cache-Control: no-cache
Accept-Encoding: multipart/form-data
--null
< path/to/my/file
--null--
What is the correct syntax for performing multipart uploads?
Here's my .http file. Worked.
POST http://127.0.0.1:8000/v1/dataSource/1/table/
Content-Type: multipart/form-data; boundary=WebAppBoundary
--WebAppBoundary
Content-Disposition: form-data; name="csv_files"; filename="insight_modeling_base_node.csv"
< /home/core/Code/work/KG_test/data/insight_modeling_base_node.csv
--WebAppBoundary--
In your case, try adding boundary=null. Or just copy what I pasted here and make some adaptation.
Related
I'm uploading a screenshot failure png to Test Rail via their API - Here's the code that works in 106:
Request = new RestRequest("/index.php?/api/v2/add_attachment_to_result/85)
.AddHeader("Content-Type", "multipart/form-data")
.AddFile("attachment", "C:\Source\screenshot.png");
IRestResponse AddAttachmentResponse = Client.Post(Request);
The only thing I changed after the upgrade to v107 is the last line:
RestResponse AddAttachmentResponse = Client.PostAsync(Request).GetAwaiter().GetResult();
I now get an error back from the Test Rail API "Bad Request" - here's the documentation on their API: Test Rail Add Attachment API doc - I know the http engine has changed in 107 - what do I need to do differently now?
UPDATE:
It appears that v107 is not sending the Content-Type in the header - here's the output from HttpTracer:
==================== HTTP ERROR REQUEST: [POST] ====================
Authorization: Basic TokenRemoved
Accept: application/json, text/json, text/x-json, text/javascript, *+json, application/xml, text/xml, +xml, *
User-Agent: RestSharp/107.1.1.0
Accept-Encoding: gzip, deflate, br
Cookie: tr_session=7cef485e-1aca-46bb-a773-9d9f5d410ee6
--8eef1c58-a3df-4ddb-a1c5-e081ccf90709
Content-Type: application/octet-stream
Content-Disposition: form-data; name=attachment; filename=Untitled.png; filename=utf-8''Untitled.png
snipped for brevity
Note there is a Content-Type in the body, but none in the header.
Issue link: https://github.com/restsharp/RestSharp/issues/1713
As we discussed, HttpTracer only shows the request headers, and Content-Type is the request header.
When debugging this issue (and a couple of other related issues), we found out that the issue was caused by the server not being able to handle name and filename parameters in the form part (Content-Disposition header) if they are not wrapped in quotes. Strangely enough, adding content disposition directly using ContentDispositionHeaderValue doesn't add quotes by default. After adding them manually it started to work:
fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data") {
Name = $"\"{file.Name}\"",
FileName = $"\"{file.FileName}\""
};
My answer is for anyone who experienced a similar issue with 107.1, the latest alpha and the next stable version should handle this properly.
The eBay CSV Manager enables to upload a CSV file to mark all paid and sent items as sent in eBays seller tool. My Excel Macro creates such a CSV file. Now, I want to upload this file via HTTP Post Request.
In eBays CSV Manager manual they say:
Files can only be uploaded via Token. This Token has to be send with the file every upload. It is virtually the key for the entry to the CSV Manager.
I already have the Token.
It goes on to say that
a HTTP Post request has to be sent to the eBay CSV Manager Server to upload the file via script. The HTTPS connection has to be started and the data has to be send together with the Token to the CSV Manager web adress https://bulksell.ebay.com/ws/eBayISA...ExchangeUpload
eBay has an example for the request in its CSV Manager manual:
POST /path/to/upload/script HTTP/1.0
Connection: Keep-Alive
User-Agent: My Client App v1.0
Host:
https://bulksell.ebay.com/ws/eBayISA...ExchangeUpload
Content-type: multipart/form-data;
boundary=THIS_STRING_SEPARATES
Content-Length: 256
--THIS_STRING_SEPARATES
Content-Disposition: form-data; name="token"
12345678987654321
--THIS_STRING_SEPARATES
Content-Disposition: form-data; name="file";
filename="listings.csv"
Content-Type: text/csv
... contents of listings.csv ...
--THIS_STRING_SEPARATES
The explanation of the example is:
State which method has to be applied to the ressource:
POST /path/to/upload/script HTTP/1.0
Connection type, user-agent and information to the host:
Connection: Keep-Alive
User-Agent: My Client App v1.0
Host:https://bulksell.ebay.com/ws/eBayISA...ExchangeUpload
Header with information to the content and the lenght of the file:
Content-type: multipart/form-data; boundary=THIS_STRING_SEPARATES
Content-Length: 256
Safety Token and content to be uploaded:
--THIS_STRING_SEPARATES
Content-Disposition: form-data; name="token"
12345678987654321
--THIS_STRING_SEPARATES
Content-Disposition: form-data; name="file"; filename="listings.csv"
Content-Type: text/csv
... contents of listings.csv ...
--THIS_STRING_SEPARATES
How to do the HTTP Request and how to integrate it to the VBA Code?
The concept of REST API is that you post a data file to the API end point. You need to use one of microsoft http add-on to conscruct the payload which contains the header and body and post it to the require API.
You would have multi part in your macro to achieve this function
A login function where you would store the token
A body constructor where you would read your excel data and transform it into a json format.
A header constructor
A post function where post the relevant data to the gateway api using the microsoft http document handler.
But if you are planning to send the CSV as data then its best to write a vbscript to quickly post the file to the API.
I'm trying to send a file in Postman native to test our API, but I can't get it sent. I've set Request method POST, chosen BODY and added a file (using the file selector) and given the file the key I want it to have. I've also added another key-value (string), which gets sent. This is the request:
POST /api/user/1901594/17406/foto HTTP/1.1
Host: hidden.domain.com
tp-api-token: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6ImF4a3Jpc3RpYW5zZW4iLCJ0dGwiOjE1NTYwNDQ0NDh9.7MAp43_4jnPM_QQluc2Ozx-QBowjCIqQzJ8sn9Y7HG0
cache-control: no-cache
Postman-Token: 8c14c293-f769-4391-90a3-c070cba1393a
Content-Type: multipart/form-data; boundary=----
WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="foto"; filename="C:\Users\ander\Downloads\bilder tilhenger\DSC_0178.JPG
Content-Disposition: form-data; name="unikID"
asdf2398
------WebKitFormBoundary7MA4YWxkTrZu0gW--
As you can see the filename is added to the request, but not the actual file itself (it should be, shouldn't it?)
Is this a bug, or am I doing something wrong?
Nothing wrong with the Postman request. It was the PHP extension php-fileinfo who wasn't installed on our new server.
I have a WCF service which I make API requests to.
This API call returns a JSON response object and also is able to return it in GZIP compression as well when "gzip" value is used in "Accept-Encoding" header.
The problem is when I try to get the response in GZIP, Postman shows "Could not get any response" although I see response and response's content are OK (200 status code) in Fiddler and can easily decompress the response content in my C# client.
I took a look in Postman Console but all I see is "Error: incorrect header check".
I hardly tried to find any documentation regarding this header check but couldn't find any.
These are the request headers:
POST /correction/v1/document?lang=US HTTP/1.1
Content-Type: text/plain
Accept-Encoding: gzip
User-Agent: PostmanRuntime/7.6.0
Accept: */*
content-length: 630
Connection: close
These are the response headers:
HTTP/1.1 200 OK
Content-Length: 512
Content-Type: application/json; charset=utf-8
Content-Encoding: gzip
Server: Microsoft-HTTPAPI/2.0
Date: Sun, 24 Feb 2019 14:05:50 GMT
Connection: close
The only thing I suspect is wrong is this message from Fiddler:
I integrated this code into mine in order to use GZIP in WCF.
https://github.com/carlosfigueira/WCFSamples/tree/master/MessageEncoder/GZipEncoderAndAutoFormatSelection
Basically, it captures the response before returning to client and use GZipStream for compression.
I got the same issue, I added the following header to fix this issue.
Accept-Encoding : *
I was able to solve a similar issue by using the header Accept-Encoding: */* or if you want to be specific do Accept-Encoding: */* that way the HTTP client will be able to process the response based on the type of encoding received, in the case of a gzip, it will decode the response and show it as normal text.
For me, I removed 'Accept-Encoding' in the request header.
I got this issue when the REST service was returning a zip content (aka. WinZip format). I solved the error by compressing the data using 7zip to produce true gzip format.
I'm facing issue while uploading a file through JMeter. When file was uploaded manually, it was successful. The file is CSV file and it's contents are: Mr.,Perf,Driver4,LIC1,10003,12/31/2025,12/31/2025,CA,USA
Request Captured in fiddler:
POST https://WebSiteName/MainPage/Drivers/UploadDrivers HTTP/1.1
Accept: text/html, application/xhtml+xml, */*
Referer: https://WebSiteName/MainPage/Drivers/Main
Accept-Language: en-US
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko
Content-Type: multipart/form-data; boundary=---------------------------7e21cd231003b8
Accept-Encoding: gzip, deflate
Host: WebSiteName
Content-Length: 691
Connection: Keep-Alive
Cache-Control: no-cache
Cookie: intercom-lou-zjtmncjn=1; __utma=1.1400002961.1527162610.1533116464.1533118526.10; __utmz=1.1527162610.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); MainPageusername=akalambe; MainPagerememberchkbox=true; __utmv=1.|1=FleetId=67468d0b-4f3d-4693-9d06-ed226d27198c=1^2=UserId=f0467301-c934-4354-87a1-d875f56359de=1^3=RegionName=FW02=1; __utmt=1; __utmb=1.2.10.1533118526; AWSELB=6703C92B1A36D2911BDDEF67F947B6D8FA09E46F7AB993BF5EEE818483244FFE1C5B9ED7D743F6F7966ACAFFC21671252299970FE39D531FCECB082F45AABB8B505FB5E6AA; __utmc=1; DirectorAuth=CDBE3FDB1C993ABF0A408A386AFEDC5DFA8B423E6B55F11100AC49D6DD5FB5D66721E8F3111D77E689ABAA72CF5D8E88A94C07F3F58B310CDCFD350A604038BF703448EA9E3E21F4F815E8288C781E64C6E1180FDF81426C1F3F24CF513E5C4026072351C5BEC06F0C28EBA57502937D551A7CEFA67BBAE5FF2C59137A33498B341ED0AD90B83919ACB0A1630B9C80AFC9992D7004C1DF9D7AE042420BE76EA2AB96D43A5E7F8956BDE18ACC8BE8AF813AE476A376F58C3750E3A02B8BC148006B427790F7AD8B7E88276D5CEAEC16D8624E7D087DB8D06AE7727DF4F71A6EB01798E119D71D13E8B6556F21CDB6B58D30FD0078D57E1E4C334F5600C72DA0A636F14529506298657A45E5BD009A556EDB6837BBEA1B26F71EF8304A4401F47B12785D5F; MainPageUserPreferredLocale=en-US; DirectorSession=oceg01jzjoqjq5iybq4mg3im
-----------------------------7e21cd231003b8
Content-Disposition: form-data; name="file"; filename="EntityImportTemplate.csv"
Content-Type: text/plain
Title,FirstName,LastName,LicenceClass,LicenceNo,ExpirationDate,LastPhysical,LicenceState(Abbreviated),"LicenceCountry(Abbreviations include: USA,CAN,MEX,AUS,NZ)"
Mr.,Perf,Driver4,LIC1,10003,12/31/2025,12/31/2025,CA,USA
-----------------------------7e21cd231003b8
Content-Disposition: form-data; name="Filename"
EntityImportTemplate.csv
-----------------------------7e21cd231003b8
Content-Disposition: form-data; name="OwnerId"
67468d0b-4f3d-4693-9d06-ed226d27198c
-----------------------------7e21cd231003b8—
Response Captured in fiddler:
{"Success":true,"ImportMessages":[{"ErrorDescription":"Driver verified","Tag":null,"TimeStampUtc":"/Date(1533123584180)/","MessageType":0,"Text":"Driver verified"}]}
But response in JMeter for same file upload is:
{"Success":false,"ImportMessages":[{"ErrorDescription":"Import could not start - Object reference not set to an instance of an object.","Tag":null,"TimeStampUtc":"/Date(1533717886829)/","MessageType":2,"Text":"Import could not start"}]}
JMeter HTTP Request
HTTP Header Manager
HTTP Cookie Manager
Result
The way of building your upload request is quite flaky, I would rather recommend using Files Upload tab of the HTTP Request sampler and specify your CSV file there like:
Also don't forget to tick Use multipart/form-data for POST box
In general the best way to build a file upload request with JMeter is just recording it with HTTP(S) Test Script Recorder
Copy your EntityImportTemplate.csv file to "bin" folder of your JMeter installation
Start HTTP(S) Test Script Recorder
Configure your browser to use JMeter as the proxy
Issue your upload request
The relevant HTTP Request sampler should be created under the Recording Controller
More information: Recording File Uploads with JMeter
Just go to Advanced Tab and select "Java" as implementation.I hope it will work correctly.
It mostly depends on how web application under test responds to Jmeter scripts.
For me, once I was trying to upload docx through Jmeter and it was uploaded to file share location but thrown an error - "File format is not supported" even with correct uploading API configurations as recommended.
File Path: filename.docx, Parameter name: class name of UI element used to upload document e.g. button to browse file from disk MIME TYPE: vnd.openxmlformats-officedocument.wordprocessingml.document Select 'Use multipart/form-data' It worked successfully without any error and un-corrupted document content with below configuration some how:
File Path: filename.docx, Parameter name: Blank (Yes.. do not provide any value in here for Parameter column just leave it blank) MIME TYPE: vnd.openxmlformats-officedocument.wordprocessingml.document Deslect 'Use multipart/form-data'