Uploading images via gatling

Hi,

I’m trying to upload an image via Gatling but keep getting 413s from the server. It clearly works via the web front end so I suspect something is wrong with my method of creating the request.

Here’s what I’m doing:

val headers = Map(
“”“Accept”"" → “”“text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8"”",
“”“Content-Type”"" → “”“multipart/form-data; boundary=---------------------------19577276091468095107188555610"”")

exec(http(“Upload_Image”)
.post( “”"/photo-upload""")
.headers(headers)
.bodyPart(ByteArrayBodyPart(“image.jpg”, photo)
.check(status.is(200))

Photo is an image converted to a byteArray.

Is there something I’m missing here?

Thanks,

Jim

413 is Request entity too large, so it seems your byte array is too large for your service.

“413 is Request entity too large, so it seems your byte array is too large for your service.”

The application can upload images, my question was how do I via Gatling?

I don’t envisage changing the application to support the tool. The recorder generates a .txt file which uploads fine but I’d like to dynamically load the data. My question again is how do I POST an image via Gatling?

"413 is Request entity too large, so it seems your byte array is too large
for your service."

The application can upload images, my question was how do I via Gatling?

I don't envisage changing the application to support the tool.

No, you didn't get me: your application complains that the upload byte
array is too large (larger than it's configured limit).
Either there's a problem with the way you generated your byte array (it's
indeed too large), or with the way your application reports a 413
(something else happens, such as an invalid message, but your application
wrongly replies 513 instead of the real message).

The recorder generates a .txt file which uploads fine but I'd like to
dynamically load the data. My question again is how do I POST an image via
Gatling?

Have you read the documentation?
http://gatling.io/docs/2.0.3/http/http_request.html#multipart-form

Just to finish up where I got with this last week,

This worked for me:

.bodyPart(RawFileBodyPart(“photo”, ImageUtils.createOnFileSystem(new Image().getAbsolutePath()).contentType(“image/jpeg”)).asMultipartForm

Ideally I wouldn’t have like to store the image but the ByteArrayPart wasn’t working (maybe server restrictions).

So you’re saying that the very close below doesn’t work for you?

.bodyPart(ByteArrayBodyPart(“photo”, bytes).contentType(“image/jpeg”)).asMultipartForm

Would you mind sharing a problematic file, please?
Also, do you use http or https?

The file is an individuals image so I can’t share unfortunately. It’s also over HTTP.

I looked into the server logs and found the validation failures where it looked for the content-disposition type when using a byte array. That this means in plain English is it needed a file name or else it didn’t recognise it as a file. The correct method is:

.bodyPart(ByteArrayBodyPart(“photo”, photoArray).fileName(“photo.jpg”).contentType(“image/jpeg”)).asMultipartForm

Thanks for looking into it, was more of a thinking out loud exercise in the end.

Glad you found it out.