Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File is not uploading via ZenodoApi --> ZenodoApiFiles --> upload() method #9

Open
mansu1101 opened this issue Oct 21, 2020 · 1 comment

Comments

@mansu1101
Copy link

I am using this npm package to upload my files to zenodo bucket, I am getting 200 status code response while calling upload API( internally PUT API of zenodo)

Here is my code of reference

`const fs = require('fs');
const zenedo = require("zenodo");
const api = new zenedo({
token: '',
protocol: 'https',
host: 'sandbox.zenodo.org',
pathPrefix: '/api/'
});
async function uploadToZenodo() {
const fs = require('fs').promises;
const base64String = await fs.readFile('/home/user/Desktop/data/testFile.pdf', {encoding: 'base64'});
//console.log(base64String);
try{
api.files.upload({
bucketId: '',
filename: 'newFileName.pdf',
data: 'data:image/pdf;base64,' + base64String
}).then(function (response) {
console.log("response is coming for upload file :", response.data);
}, (err)=> {
console.log("Error while uploading file :", err.response);
});
} catch (e) {
console.log("Exception while uploading file :", e);
}
}

uploadToZenodo();`

This uploadToZenodo() method is working fine but when I click on the uploaded file I am not able to view my download file. Because I think file which we upload via API is not saving the content of file properly.

Here in this upload method I am not sure what should be data type for upload({
deposition, //mydoi id
filename, //new file name
contentType = 'application/octet-stream',
data // don't know what should be the value of this property like a file or base64 or somthing else?
}}

I tried all the formats but it's not uploading file content.

@targos
Copy link
Member

targos commented Feb 25, 2021

data can be anything supported by the axios library. A string, an object (which will be sent as JSON), a Buffer, a stream...
So if you're reading a file in Node.js, you can use fs.readFile(filepath) (without base64 encoding), or fs.createReadStream(filepath).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants