-
Notifications
You must be signed in to change notification settings - Fork 16
Open
Description
The nodejs example at: https://github.com/zenodo/developers.zenodo.org/blob/master/source/includes/overview/_quickstart.md does not work for me.
I manage it to work using the follow code:
const fs = require('fs');
const axios = require('axios');
const filePath = '<FILE_PATH>'; // Replace with file path
const bucketURL = '<BUCKET_URL>'; // Replace with bucket url
const fileName = '<FILE_NAME>'; // Replace with file name
const token = 'TOKEN'; // Replace with token value
// Read file as a stream
const stream = fs.createReadStream(filePath);
// Create request
let url = `${bucketURL}/${fileName}`;
let headers = {
'Content-type': 'application/octet-stream',
'Content-Length': fs.statSync(filePath).size //THIS IS IMPORTANT,
'Authorization': `Bearer ${token}`
}
const requestConfig = {
headers: headers,
}
axios.put(url, stream, requestConfig).then(response => {
console.log(response.data);
}).catch(error => {
console.log(error.response.data);
});
Using FormData
changes the Content-type
to multipart-form
and the bucket endpoint does not accept it. It requires application/octet-stream' (binary). Additionally, the
Content-Length` must be set.
Hope this can help others.
Thanks.
Metadata
Metadata
Assignees
Labels
No labels