Upload a file to COS Files API with Node.js (fetch)
I had to give up with node-fetch as I was stuck forever. I switched to Unirest and works perfectly.
unirest.post('https://api.hubapi.com/filemanager/api/v2/files')
.headers({
'Authorization': 'Bearer ' + hubspotParams['accessToken'],
'Content-Type': 'multipart/form-data'
})
.query({
'overwrite':'true', // if you want to overwrite the file when it already exists
'hidden':'false' // if you want the file to be visible in the File Manager
})
.field('folder_paths', '...') // if you need to change the upload directory
.field('file_names','...') // if you need to change the file name
.attach('file', fs.createReadStream('file.txt')) // Attachment
.end(function (response) {
console.log(response.body);
});