Java - Help on POST Multipart file upload.

Hello All,

Following is my Gatling code and POST request body. Getting the “The input message is not readable” response. I have read the documentation, but not sure what is wrong with the request definition.

.bodyParts(
StringBodyPart(“name”, “content”)
.contentType(“application/pdf”)
.fileName(“computerdatabase/ccpupload/Test.pdf”)
)

------WebKitFormBoundarypyzZDBVYhFan06by
Content-Disposition: form-data; name=“content”; filename=“Test.pdf”
Content-Type: application/pdf

%PDF-1.7
%
1 0 obj
<</Type/Catalog/Pages 2 0 R/Lang(en-US) /Metadata 12 0 R/ViewerPreferences 13 0 R>>
endobj
2 0 obj
<</Type/Pages/Count 1/Kids[ 3 0 R] >>
endobj
3 0 obj
<</Type/Page/Parent 2 0 R/Resources<</Font<</F1 5 0 R>>/ExtGState<</GS7 7 0 R/GS8 8 0 R>>/ProcSet[/PDF/Text/ImageB/ImageC/ImageI] >>/MediaBox[ 0 0 612 792] /Contents 4 0 R/Group<</Type/Group/S/Transparency/CS/DeviceRGB>>/Tabs/S>>
endobj


29105
%%EOF
xref
0 0
trailer
<</Size 15/Root 1 0 R/Info 9 0 R/ID[<0DB784A711305F4FBF218D9D2F83A31B><0DB784A711305F4FBF218D9D2F83A31B>] /Prev 29105/XRefStm 28845>>
startxref
29561
%%EOF
------WebKitFormBoundarypyzZDBVYhFan06by–

Regards,
Bharath.

Hello,

There’s no way to investigate unless you provide an online or portable sample app we can reproduce the issue against.

Regards,

Hello Stephan,

This is an internal application that can’t be accessed outside. If you can help me in constructing the request body as shown below, I will try to run the code in our environment. Also attaching the Fiddler snapshot of the request body.

I am expecting the request body to be as follows.

-----------------------------7334150184050509724267004786
Content-Disposition: form-data; name=“content”; filename=“Test.pdf”
Content-Type: application/pdf

%PDF-1.7
%����
1 0 obj
<</Type/Catalog/Pages 2 0 R/Lang(en-US) /Metadata 12 0 R/ViewerPreferences 13 0 R>>



%%EOF
-----------------------------7334150184050509724267004786–

But in the Gatling, the request body is getting constructed as below, I think it is not correct.

body:MultipartFormDataRequestBody{boundary=[57, 121, 78, 85, 110, 45, 97, 80, 67, 109, 55, 121, 110, 82, 76, 71, 111, 67, 51, 88, 88, 68, 86, 107, 80, 56, 97, 89, 110, 109, 53, 66, 120, 112, 79], contentType=‘multipart/form-data; boundary=9yNUn-aPCm7ynRLGoC3XXDVkP8aYnm5BxpO’, content=Part{name=‘name’, charset=null, transferEncoding=‘null’, contentId=‘null’, dispositionType=‘null’, contentType=‘application/pdf’, customHeaders=, content=[B@53ff6825}

Regards,
Bharath.

You have StringBodyPart wrong.

.bodyParts(
StringBodyPart(“name”, “content”)
.contentType(“application/pdf”)
.fileName(“computerdatabase/ccpupload/Test.pdf”)
)

Here:

  • “name” is the name of the part
  • “content” is the content of the part
  • fileName is the value of the filename attribute in the part’s Content-Disposition header
    You most likely want to use RawFileBodyPart instead.

Hello Stephan,

The following code worked

.bodyPart(
RawFileBodyPart(“content”, “computerdatabase/ccpupload/Test.pdf”)
.contentType(“application/pdf”)
.fileName(“Test.pdf”)
)

I was giving the file path incorrectly, it should be in the RawFileBodyPart and not in the .fileName, also the StringBodyPart instead of RawFileBodyPart.

Your site documentation is awesome except regarding the file POST method. I suggest adding a few more examples by showing the request body and corresponding Gatling code.

Thank you for your response.

Regards,
Bharath.

Hi!

I suggest adding a few more examples by showing the request body and corresponding Gatling code.

Contributions are welcome! (There is a link at the end of each page of the documentation)

Cheers!

Hi Bharath,

Please, avoid sending direct messages, this is a mailing list and should stay public discussion.

As suggested by GitHub directions: you can “Fork this project and edit the file”, then submit a pull request.

As most open source project on GitHub, we are in Fork and Pull Request model

Useful links:

Cheers!