-
Notifications
You must be signed in to change notification settings - Fork 0
3.1.3 SUBMOD.001.003 : Get AML File by id
The submodule to get an AML file by id provides the functionality to get a file by id. This function is needed when the user wants to edit a specific AML file. He opens the file and gives an id from the GUI.
The needed /file/:id and /file/:id/download GET endpoints are defined below. Here we are using the created FILE model to get a file document by _id from MongoDB by using ´FILE.getFile(_id, callback)´.
const FILE = require('./models/file');
...
app.get('/file/:id', (req, res) => {
FILE.getFile(req.params.id, (err, file) => {
>> 6.2 Response data
});
});
app.get(`/file/:id/download`, (req, res) => {
FILE.getFile(req.params.id, (err, file) => {
>> 6.3 Response download
});
});
...
After finding of our document we need to check if there is no error. If an error ocurred, we are sending a JSend with status 'error' and a defined message back. If everything was correct and a file could we found, we are modifying our base64 to ASCII. That because we need ASCII to modify our content of the file.
...
if (!err && file) {
let newObj = {name: file.name, content: Buffer(file.base64, 'base64').toString('ascii')}
res.status(200).send({ status: 'success', data: newObj });
} else {
res.status(200).send({ status: 'error', message: 'Unable to get file' });
}
...
After finding of our document we need to check if there is no error. If an error ocurred, we are sending a JSend with status 'error' and a defined message back. If everything was correct and a file could we found, we are sending it as a JSend with status 'success' back.
...
if (!err && file) {
res.status(200).send({status: 'success', data: file});
} else {
res.status(200).send({status: 'error', message: 'Unable to download file'});
}
...
© LMF.software - Jonas Bihr, Namid Marxen, Johannes Emanuel Timter & Nils-Christopher Wiesenauer
For any question regarding our software contact us on here on GitHub.
- Home
- 1. SRS (System Requirements Specification)
- 2. SAS (System Architecuture Specification)
- 3. MODs (Modul Documentations)
- 4. MM (Meeting Minutes)
- 5. User Manual
- 6. Systemtestplan
- 7. Systemtestreport