Yarn:
yarn add hapi-fenixedu-drive
NPM:
npm install --save hapi-fenixedu-drive
server.register({
register: require('hapi-fenixedu-drive'),
options: {
url: 'your-drive-url',
appId: 'your-drive-app-id',
appSecret: 'your-drive-app-secret',
username: 'your-drive-username'
}
}, (err) => {
if (err) {
console.error('Failed to load plugin:', err);
}
});
api.route({
method: 'POST',
path: '/upload',
config: {
payload: {
output: 'stream',
parse: true,
allow: 'multipart/form-data'
}
},
handler: function (request, reply) {
request.storeFile({
filename: filename,
file: request.payload.file,
path: path
}).then((fileInfo) => {
//Store fileInfo in a database for later retrieval...
});
}
});
api.route({
method: 'GET',
path: '/',
handler: function (request, reply) {
const fileId = ... // Retrieve this fileId from a database for example...
reply.fileFromDrive({
fileId: fileId
}, (err, fileStream) => {
//handle error if exists
reply(fileStream);
});
}
});