Yarn:
yarn add fenixedu-drive
NPM:
npm install --save fenixedu-drive
const drive = require("fenixedu-drive");
const client = drive({
"url": "https://your-fenixedu-drive-url"
"serviceAppId": "your-service-app-id",
"serviceAppSecret": "your-service-app-secret",
"appId": "your-app-id",
"appSecret": "your-app-secret",
"username": "the-username-uploading-files"
});
...
client.storeFile({
filename: "my-filename.pdf",
file: fs.readFileSync("./file.pdf"),
path: "my/drive/abs/path"
username: "my-username" // defaults to username in config when omitted
}).then((fileInfo) => {
// fileInfo is a JSON object like { id: <the-file-id>, path: <file-path-on-drive>, size: <size-in-bytes> }
}).catch((error) => {
//handle the error
});
...
client.downloadFile({
fileId: <the-file-id>
}, (err, fileStream) => {
if(err) {
throw new Error("Can't download the file");
} else {
fileStream.pipe(fs.createWriteStream("./output"));
}
});