Forum Discussion

adithyaram93's avatar
adithyaram93
New Contributor
2 years ago

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

 

  • JoostDG's avatar
    JoostDG
    Frequent Contributor

    Answer from smartbear support below.

    The links they suggested did not provide a solution/workaround. I am playing around a bit on how to construct / adapt the (raw)request payload and send it again with proper content-type, but so far no luck in finding a workaround that solves it. So only solution might be to wait for RIA-22427 :'-(

    Thank you for reaching out to SmartBear support. We have received your case and we are happy to help.

    We understand your concern. We already have an enhancement request in place for your request RIA-22427. However, we do not have an ETA on when this enhancement will be implemented in the application.

    You can alternatively check this:

    For the content type to be application/json, I would suggest you uncheck the Post QueryString. Once the option is unchecked, the Media type will display it: https://support.smartbear.com/readyapi/docs/requests/attachment/rest.html

    https://support.smartbear.com/readyapi/docs/functional/steps/http-request.html

    https://community.smartbear.com/discussions/readyapi-questions/how-to-pass-multipartform-data-request-schema-in-post-request/192169

    Hope this was helpful. Please feel free to reach out to us in case you have any other queries.

    Have a great day. Thank you!

  • JoostDG's avatar
    JoostDG
    Frequent Contributor

    Hi richie . Digging up this old post as I'm also confronted with this issue and I believe the original question isn't answered. I found a stackoverflow post which clearly explains the issue: https://stackoverflow.com/questions/78076769/soapui-readyapi-multi-part-form-data-rest-request-how-to-set-content-type-of

    So next to a normal file, we also need to send a json object for another query parameter called "myInfo". I tried 3 ways in ReadyAPI 3.52 to achieve this, but all fail to achieve my goal. More info on these 3 with test data from the stackoverflow post:

    1. The way the original poster tried it in stackoverflow: I tried to add the json value in the query parameter.  The raw view shows the json payload, but the Content-Type: application/json is missing, and our application does not accept it without this header (Content-Type 'application/octet-stream' is not supported). I have no way of adjusting this query parameter's setting to set the content-type.
    2. In the payload window, underneath the "media type" selection I added the json payload, like {"myInfo" : {"firstName" : "John", "lastName", "Doe", "middleInitial" : "A"} }. Then the Content-Type: application/json is there, but no Content-Disposition: form-data; name="myInfo" , which makes our application saying it's missing the "myInfo" parameter. 
    3. I tried to pack my json into another file (next to my normal attachment "pdfFile"). The the readyAPI reads out that file and sends the json object, but again, not with proper application/json header but with Content-Type: application/octet-stream & Content-Transfer-Encoding: binary

    The thing is, if I can send it like the poster on stackoverlfow indicates, so 

    Content-Disposition: form-data; name="myInfo" Content-Type: application/json

    it will work, as I can achieve that via postmen. It seems to me a limitation in ReadyAPI that blocks me... 

    FYI: Raised support ticket 00667624 to address this.

  • richie's avatar
    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