Hello,
Trying to POST a file (in form pdf) to Files API using the Node SDK, but getting back the following error:
" [Symbol(Response internals)]: {
url: ‘https://api.hubapi.com/filemanager/api/v3/files/upload’,
status: 415,
statusText: ‘Unsupported Media Type’,
}"
CODE:
--------------------------------------------------------------
async function uploadFile(filePath) {
console.log("calling uploadFile() for file: ", filePath);
const formData = new FormData();
formData.append(“folderPath”, ‘/’);
var options = {
access: ‘PUBLIC_INDEXABLE’,
ttl: ‘P3M’,
overwrite: true,
duplicateValidationStrategy: ‘NONE’,
duplicateValidationScope: ‘ENTIRE_PORTAL’
};
formData.append(“options”, JSON.stringify(options));
formData.append(“file”, fs.createReadStream(filePath));
const response = await hubspotClient.apiRequest({
method: ‘POST’,
path: ‘/filemanager/api/v3/files/upload’,
body: formData,
defaultJson: true,
headers: {
“Content-Type”: “application/json”
}
});
console.log(response);
}
--------------------------------------------------------------
I have seen many other threads in this community around this error, but they all just suggest setting the Content-Type header, but I am already doing that.
Any help would be greatly appreciated.
Thanks!