"use strict"; const { ROOT_PATH, LIB_PATH, MODELS_PATH, API_CONFIG } = process.env; const { downloadFile } = require(`${ROOT_PATH}/${LIB_PATH}/Misc`); const apiConfig = require( `${ROOT_PATH}/${API_CONFIG}` ); const s3Bucket = apiConfig.S3.bucket; const s3BucketKey = apiConfig.S3.load_attachments_key; const getAttachmentFile = async(req, res) => { try{ const attachmentId = req.params.id; const file = await downloadFile( s3Bucket, s3BucketKey, attachmentId ); res.attachment( attachmentId ); res.setHeader('Content-Type', file.ContentType ); res.send( file.Body ); }catch( error ){ console.error( error ); res.status(500).send({ error }); } } module.exports = { getAttachmentFile };