feat: getting presigned url of the uploaded attachment

This commit is contained in:
Ahmed Bouhuolia
2024-05-29 16:16:08 +02:00
parent e7871e34a9
commit ceb133e29a
7 changed files with 124 additions and 17 deletions

View File

@@ -51,6 +51,12 @@ export class AttachmentsController extends BaseController {
this.validationResult,
this.unlinkDocument.bind(this)
);
router.get(
'/:id/presigned-url',
[param('id').exists()],
this.validationResult,
this.getAttachmentPresignedUrl.bind(this)
);
return router;
}
@@ -185,4 +191,27 @@ export class AttachmentsController extends BaseController {
next(error);
}
}
/**
* Retreives the presigned url of the given attachment key.
* @param {Request} req
* @param {Response} res
* @param next
*/
private async getAttachmentPresignedUrl(
req: Request,
res: Response,
next: any
) {
const { id: documentKey } = req.params;
try {
const presignedUrl = await this.attachmentsApplication.getPresignedUrl(
documentKey
);
return res.status(200).send({ presignedUrl });
} catch (error) {
next(error);
}
}
}