Update Content-Type in Attachment before submission
After I attach a file to REST request and send it successfully, I am seeing name also along with Content Type in Raw request tab
and due to which i am not getting few expected parameter values in response.(As explained by the developer )
Ex:- Actual value:- Content-Type: image/png; name=2014-05-12_1220.png
Expected value:- Content-Type: image/png;
As i have not put name in Request attachment Content-Type ,I think it is getting appended automatically.
Is there any way to remove "name=2014-05-12_1220.png" from the Content-Type?
I am guessing this has to be done before request is submitted (through some groovy code in event handlers but not sure.)
Request is POST request with Media Type= multipart/form-data and Content-Disposition: form-data; in payload.
I've also added Attachment and Raw Request screenshot.
please help me in getting this resolved?
Regards,
Saurabh
Hi everyone,
I had a discussion with customer support regarding this issue, and they suggest the solution.
To specify your content type and remove name of the file after it, you should add event handler to the request. Steps are the next:
1) Click on your project through the navigator then click on the "Events" button on the top right of the application (underneath the LoadUI tab)
2) Click the green plus button to add a new event and then select the "RequestFilter.filterRequest" Event Handler
3) Click on the RequestFilter (if it's not selected already) and copy+paste the below script into the box below:def bodyPart = context.getProperty("httpMethod").requestEntity.message.content.getBodyPart(0) // get a part by number, it starts with 0 bodyPart.removeHeader("Content-Type") bodyPart.addHeader("Content-Type", "application/content-type+xml") // specify the value without the name parameter
The above script completely removes the Content-Type Header from the raw request and replaces it with only the desired content type (so in this case, application/content-type+xml).
4) Afterwards, please run your request with the attachment (and with no parameters).Please pay attantion that this part
.getBodyPart(0)
is used because I'm working with xml attachments, so for other content types script may differ.
This solution resolved my problem, so I hope it will help you