Forum Discussion
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
- richie2 years agoCommunity Hero
Hey adithyaram93
I remembered I'd had this issue way back - eventually I found the post
this worked for me
cheers,
rich
- adithyaram932 years agoNew Contributor
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
- richie2 years agoCommunity Hero
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 -->
and this -->
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
Related Content
- 4 years ago
- 11 years ago
Recent Discussions
- 5 days ago
- 9 days ago