I’ve been trying calling the upload API for box in node.js application and keep getting 415 Unsupported_Media_Type. I gave the correct parent id. Also tried using both parent_id and parent: { ‘id’: ‘12345’}
response.status = 415
response.statusText = Unsupported Media Type
I also tried "Try this API’ on the developers page and just get ‘An unknown error occured’. When tried to get more details from the browser developer tools then I see that the call just returned as above 415 and unsupported media type message.
If I include 'Content-type" header with multipart/form-data then it doesn’t find the file part.
What is the wrong with the following code?
PS: I do not want to use SDK.
var parent = ‘12345’;
var token = 'Bearer ’ + accessToken;
const url = 'https://upload.box.com/api/2.0/files/content';
const fileData = fs.createReadStream("c:\\Work\\box-development\\CustomerRequest.txt");
let formData = new FormData();
formData.append('attributes', "{"name":"newfile.txt", "parent_id":"12345"}");
formData.append('file', fileData);
try{
let response = await fetch(url, {
method: 'POST',
body: formData,
headers: {
'Authorization': token
}
});
let responseData = await response.text();
console.log(response.status);
console.log(response.statusText);
console.log(responseData);
} catch (err) {
}