Hello everyone,
I have an exposed REST API for file uploading. One of the PUT method has 2 input parameters:
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.':
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.
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,
})
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.