25
Views
2
Comments
Solved
Error: 'Failed to parse JSON request content' for uploading JSON file as binary input
Application Type
Reactive
Service Studio Version
11.55.24 (Build 64186)

Hello everyone,

I have an exposed REST API for file uploading. One of the PUT method has 2 input parameters:

  • InFileUID: File Identifier receive in URL.
  • InBinary: Binary Data receive in Body.

Here is how I invoke the PutPresignedUrl_Single method using fetch() in JavaScript:

The REST API works fine for all file types except JSON files, which returns status 400 with message 'Failed to parse JSON request content.':

  • Browser 'Network' tab:

  • Browser 'Console' tab:

  • Service Studio Error log:

I have also tried using Postman and got the same error.

Based on some other forum posts, I believe this error happens when OutSystems tries to parse the JSON file as a JSON input instead of Binary Data as defined in the REST API.

Please let me know if there are any suggestions to fix this error.

Thank you guys in advance.

2023-06-13 12-29-43
Sakthivel P
Solution

Hi @Trac Duc Anh Luong,

Please try changing the content-type as follows.

fetch(output.OutUrl, {

  method: "PUT",

  headers: { "Content-Type": "application/octet-stream" }, 

  body: file,

})

UserImage.jpg
Trac Duc Anh Luong

Hi @Sakthivel P,

The solution worked and I was able to upload JSON files by changing the 'Content-Type' header to 'application/octet-stream' and passing the file.type as another input parameter of the GetPresignedUrl_Single action.

Thank you for your answer.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.