Java - Help on POST Multipart file upload.

56 views
Skip to first unread message

Bharath Marrivada

unread,
Jan 17, 2022, 2:06:21 AM1/17/22
to Gatling User Group
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.

Stéphane LANDELLE

unread,
Jan 17, 2022, 2:54:25 AM1/17/22
to gat...@googlegroups.com
Hello,

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

Regards,

--

Stéphane Landelle

Chief Technical Officer

   

slan...@gatling.io
gatling.io
   
facebook twitter linkedin 


--
You received this message because you are subscribed to the Google Groups "Gatling User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gatling+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gatling/494cf30e-0721-40ad-8470-9df71fb7a371n%40googlegroups.com.

Bharath Marrivada

unread,
Jan 17, 2022, 4:09:09 AM1/17/22
to Gatling User Group
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.

POST-Multi-Part-Upload.png

Stéphane LANDELLE

unread,
Jan 17, 2022, 8:25:42 AM1/17/22
to gat...@googlegroups.com
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.


--

Stéphane Landelle

Chief Technical Officer

   

slan...@gatling.io
gatling.io
   
facebook twitter linkedin 

Bharath Marrivada

unread,
Jan 17, 2022, 11:16:50 AM1/17/22
to Gatling User Group
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.

Sébastien BREVET

unread,
Jan 17, 2022, 12:22:14 PM1/17/22
to gat...@googlegroups.com

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!




--

Sébastien BREVET

Backend engineer

   
sbr...@gatling.io
gatling.io

Sébastien BREVET

unread,
Jan 19, 2022, 3:32:13 AM1/19/22
to gat...@googlegroups.com

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!


On Wed, Jan 19, 2022 at 4:08 AM Bharath Marrivada <bharath....@gmail.com> wrote:
Hello Sebastien,

I have accessed the link and tried to edit the page, it says "Fork this project and edit the file". I think my user id (BharathM) needs to be added to the contribution list.
If you can add my user id, I can update the document.

Regards,
Bharath.
Reply all
Reply to author
Forward
0 new messages