Forum Discussion
Hi,
Ok, thank you for the information. I can recommend that you check the following articles:
- How to send binary data in the request payload?
- Troubleshooting issues with adding attachments to REST requests
Hey Nastya, awesome!!!
Second link helped me to inject or correct the headers in multi-part body of a request.
Thanks a ton!
I have not used attachment tab to attach a file.
Instead, I encoded a file using groovy. Groovy script does the following.
- Reads a canned json from a file and updates json nodes with right attributes
- Saves updated json to a testcase property
- Reads a pdf file and encodes in base64 format
- Saves encoded file to a testcase property
In Rest Step, I am calling above testcase properties as query parameters. Also, selected media type as "Multipart/form-data' and checked "Post QueryString" option.
In order to inject required headers I used below event handler script. (RequestFilter.filterRequest)
import org.apache.http.client.methods.HttpRequestBase import com.eviware.soapui.impl.wsdl.submit.transports.http.BaseHttpRequestTransport def bodyPart = context.getProperty("httpMethod").requestEntity.message.content.getBodyPart(0) //## get a part by number, it starts with 0 //## Add headers to json section of body bodyPart.addHeader("Content-Type", "application/json; charset=utf-8") //## specify the value without the name parameter def bodyPart1 = context.getProperty("httpMethod").requestEntity.message.content.getBodyPart(1) // get a part by number, it starts with 0 bodyPart1.removeHeader("Content-Disposition") //## delete default headder added by SoapUI //## Add headers to PDF section of body bodyPart1.addHeader("Content-Disposition", "form-data; name="+"document0"+"; filename="+"TesTDoc.pdf") bodyPart1.addHeader("Content-Type", "application/pdf") bodyPart1.addHeader("Content-Transfer-Encoding", "base64")
- Nastya_Khovrina7 years ago
Alumni
You're welcome! I'm glad to hear that the article helped you.
And, thank you for sharing your script with us!
Folks, some update and observation on my approach---
As mentioned earlier, I injected headers related to file through grovy script.
Including header "Content-Transfer-Encoding" not only adds this header but it encodes the content again. This makes file to corrupt and rejected by the file consumption module.
In order to avoid further complexity I used attachment tab to include a pdf file.