Photo Upload - Jmeter - {"reason":"Chunk-Length mismatch (found: 73800, required:73581)"} - java

I am trying to upload photo via Jmeter, below is the sample request:
URL: https://domain/.../signedresources/604a9230-..../resumable?region=US
Method: PUT
Headers:
Content-Type - image/jpeg, image/jpeg
Session-Id - 884b03...
Content-Range - bytes 0-73580/73581
Content-Length - 73581
In File Upload tab of Jmeter I have checked: Use Multipart/form-data option
File Path: /Users/sujata.../Downloads/fish.jpeg
Parameter Name: file_upload[]
MIME type: image/jpeg
Now, this request works fine when executed via Postman, and in Postman Content-Length 73581 header is not passed. The file size in bytes is 73581. However while running this request via jmeter Content-Length - 73581 header is automatically added and everytime the value is different, which is ending up with below error:
{"reason":"Chunk-Length mismatch (found: 73800, required:73581)"}
Is there any way to compute the content-length of file which we are going to upload and pass that value in the header?
I also tried explicitely mentioning Content-Length - 73581 in header but still it is not taking this valued and somehow some new value is computed and mismatch error is shown.
Is there any way to bypass this content-length computation by jmeter, or overwrite?
PUT-Request-Jmeter
Content-Type_header_added_by_jmeter

Content-Length header stands for the number of bytes in the request body. The request body begins right after the Headers. So if you're uploading just one file and there are no dynamic parts of the request - it should be the same every time you execute the request. However for multipart requests you have the boundary which is random and its length may vary, that explains the eventual differences.
It might be the case Postman sends the file in "raw" mode, i.e. not multipart. In this case you will need to untick Use multipart/form-data box in the HTTP Request sampler.
Going forward if you're able to successfully run the request using Postman you can just record it with JMeter's HTTP(S) Test Script Recorder
Start JMeter's HTTP(S) Test Script Recorder
Import JMeter's certificate into Postman
Configure Postman to use JMeter as the proxy
Copy the file you will be uploading to the "bin" folder of your JMeter installation
Run your request in Postman
That's it, now you should have appropriate JMeter configuration for the file upload.
More information: How to Convert Your Postman API Tests to JMeter for Scaling

Related

How to Send a CSV File as Request in Body

I'm trying to send a csv file as a request in body.
It's working fine for me in Postman. But I'm getting the below error in Jmeter.
{
"id":32,
"deleted":null,
"uuid":"f5cec747-4794-4e54-9c4b-58da61f30921",
"status":"Error",
"csvFileName":"",
"unsuccessfulRecords":[
"['Not Applicable', '{\\'csvFile\\': [ErrorDetail(string=\\'The submitted data was not a file. Check the encoding type on the form.\\', code=\\'invalid\\')], \\'assets\\': [ErrorDetail(string=\\'Expected a list of items but got type \"str\".\\', code=\\'not_a_list\\')]}']"
],
"successfulRecordsCount":0,
"duplicateRecordsCount":0,
"createdBy":"user",
"createdAt":"2022-12-06T09:58:51.285524Z",
"modifiedAt":"2022-12-06T09:58:51.285538Z",
"idAllowdAt":"2022-12-06T09:58:51.285538Z",
"idAllowListType":1
}
Below is the request i'm sending as part of Body Data. The REST Api accept these parameters, and afer that it imports the CSV file:
{
"csvFile": "${__FileToString(D:/Users/anabeel/Downloads/Demo/Demo.csv,,)}",
"allowlistTypeId": "1",
"createdBy": "user",
"assets": "['asset1', 'asset2']",
"uuid": "${requestIndex}",
"tags": "{'Platform Family':[{'abc123':'LinuxOS System'}]}",
"tenantId": "abc456"
}
Content-type: application/json
It seems I'm not importing the csv file the right way. Can someone please help me as I dont have much experience working with Jmeter. I also tried using CSV Data Set Config, but it didn't worked for me.
If your request "working fine for me in Postman" you can just record it using JMeter's HTTP(S) Test Script Recorder.
Configure JMeter for recording, the easiest option is going for Recording Template
Import JMeter's certificate to Postman
Configure Postman to use JMeter as the proxy
Copy your CSV file to bin folder of your JMeter installation
Run your request in Postman
JMeter will generate proper HTTP Request sampler and HTTP Header Manager
Parameterize the path to the CSV file if needed
Your JMeter request should be working fine now
More information: JMeter Performance Testing: Upload and Download Scenarios

Jmeter File upload Scenario - Issue PUT with body

I have a jmeter scenario where I need to upload a txt file of different size . To upload the file in jmeter , we enable multipart and request is of PUT type.
I am also getting put body , which is creating issue in my log files in the backend . Posting a sample request body . Is there any way where we can just send data without any data showing up under put data .
According to your screenshot you're trying to upload a file to http://www.csm-testcenter.org/test page, the page assumes HTTP POST method, not PUT.
If you're uncertain regarding proper JMeter configuration when it comes to uploading files be informed that you can just record the file upload event using your favourite browser (or another application) and JMeter's HTTP(S) Test Script Recorder. All you need to do is to copy the file to "bin" folder of your JMeter installation, this way JMeter will be able to properly capture the request and generate the relevant HTTP Request sampler and HTTP Header Manager.
More information: Recording File Uploads with JMeter

How to do correlation in HTTP Header manager which producing dynamic values

In the above picture we are facing the dynamic values in content type,so we are try to correlation for that but it is unable to read the dynamic value from the server.
Please check the correlation value which we done, Please help us on this issue.
HTTP Header Manager is defining additional request headers which you are sending with the request.
I don't really understand why you are trying to extract the value from the request header which you define yourself.
If you are trying to perform a file upload or your application expects multipart/form-data content type you can send this header automatically ticking the relevant checkbox in the HTTP Request sampler
In general I would recommend recording your test scenario using HTTP(S) Test Script Recorder, it should be smart enough to generate the relevant test plan skeleton.

Specify actual content-type of a uploaded file

I'm working on a blob upload service and I have this code that persist uploaded meta-data in the Datastore and the actual bytes into the Blobstore.
I am having issues with the Mime-Type provided by the REST client (I am using the Rest Console Chrome plugin)
This is the mime-type that is passed from the client to the server:
Mime type: multipart/form-data; boundary=----WebKitFormBoundarytxCVEFIRjPB7YIq7
However the server needs to get the "actual mime-type", that is, for example image/jpeg, image/jpeg, text/plain, etc.
Using the App Engine API I need to explicitly provide the mime-type like this:
AppEngineFile file = fileService.createNewBlobFile(entity.getMimeType());
How do I specify this? Do I need to put another header? The files that will be uploaded will vary and that the file can be up to 50MB in size (If I remember that correctly).
"Multipart" means that the data sent can have multiple parts, each with it's own mime type. Read about handling multipart form uploads on GAE.
You can use FileItemStream.getContentType() to get mime type of each part.

Add request header field to JMeter WebService(SOAP) Request

It seems like the WebService(SOAP) Request of JMeter does not include headers in the request defined in a HTTP Header Manager.
I want to send Accept-Encoding: gzip, deflate with every SOAP request of my JMeter test - is there a way to achieve that?
The workaround for me was to use the SOAP/XML-RPC Request Sampler instead of the the WebService(SOAP) Request. This one sends the configured request headers to the server.
After that I found out that the incoming compressed response was not decompressed so I filed a bug at https://issues.apache.org/bugzilla/show_bug.cgi?id=48542 and created a patch. The bug is fixed in the trunk and should be included in the current nightly build.

Categories