Ask a Question

Rest request attachments multipart form data for json file with parameterized json data

adithyaram93
New Contributor

Rest request attachments multipart form data for json file with parameterized json data

So I have been trying to do a scenario where i have two attachments for a rest request, one json file which i need to parameterize couple of fields from previous request. The problem with this is once you have cached the attachment you cannot modify it based on the previous test steps, So i have followed the following youtube link https://www.youtube.com/watch?v=iL-zehJmtWw

Used query parameter to use a locally store file of json to request but we are getting the error from response that application/octet-stream content type is not accepted

------=_Part_01_136051460.1696260652738
Content-Disposition: form-data; name="testFile"

testFile:/Path/to/file/testFile.json

 

I have used parameter like this testFile:${projectDir}/testFile.json

What should I do in this case

 

4 REPLIES 4
richie
Community Hero

Hi @adithyaram93 

 

Im responding to this cos no one else has - but it's been quite a while since I attached a file to a REST request in ReadyAPI! - but I do remember itgave me a headache!

 

The error you're getting quite often occurs when the endpoint you're hitting doesn't like either the data (in the file) youre sending or it doesnt like the Content-Type header value on your request or both.

 

I know you said you need to attach a file to a REST request and so followed the youtube vid - but have you confirmed what Content-Type header value the listening endpoint is expecting?  have you confirmed whether the header value is multipart/form-data or multipart/mixed (for attached files) or application/json for embedded files?

 

Your listening endpoint will be expecting a specific Content-Type header value and if you send the wrong one, you'll get the sort of error response you've been seeing.

 

Cheers,

 

rich

if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
richie
Community Hero

Hey @adithyaram93 

 

I remembered I'd had this issue way back - eventually I found the post

 

https://community.smartbear.com/t5/ReadyAPI-Questions/How-to-pass-multipart-form-data-request-schema...

 

this worked for me

 

cheers,

 

rich

if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta

@richie When i have tried to use file path as query parameter we dont have a way to specify the content-type here. By default ready api sends this as application/octet-stream but the end point expects application/json

Hey @adithyaram93 

 

You've kindof lost me a little - did you say you've set the ${projectDir} as a query parm?

 

Also -on your Project - did you set the 'Resource Root' Project level property to ${projectDir}?

 

OR - are you saying you've set the path to the file attachment in the 'Name' column (left hand column) in the 'Attachments' tab on your REST request?

 

In my test I attached a letter.docx file and the Content-Type column in the Attachments section auto populated with the value 'application/octet-stream'.

 

I then altered my test and attached a json file and the Content-Type column in the Attachments section auto populated with 'text/javascript'.

 

I then altered the value from 'text/javascript' to 'application/json' - submitted the request and the RAW details associated with the request displayed 'Content-Type' (associated with the attached file) was set to 'application/json'. 

 

It would help me if you could send some screenshots of the multipart/form-data Request to help understand.

 

It would help a lot if you screenshotted the RAW details of your request so we can see what's actually being generated.

Would also help if you screenshotted the Attachments tab content for the same request as well.

 

like this -->

 

richie_3-1696643433376.png

 

 

and this -->

 

 

richie_4-1696643470061.png

 

 

From a security perspective - the only thing you need to obfuscate in the screenshot is the DOMAIN portion of the URL that is associated to the your request. If you look at my screenshots - I've removed the first three quarters of the domain/host content.  Naughty people wanting to take advantage of this sort of stuff and do illegal stuff can't do anything without knowing the host/domain your endpoint uses and I've removed virtually all of the host/domain - so you can publish screenshots of this stuff.

 

the host/domain value will be Endpoint field, also displayed in your RAW content, as well as the REST Request property table (bottom left hand side of screen).  Hide/scrub out these and you can publish pics without revealing anything any nefarious person can use.

 

Cheers,

 

Rich

if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
cancel
Showing results for 
Search instead for 
Did you mean: