From bfd9c2d570f9948e6bad968e7c0e9103d15bf2a6 Mon Sep 17 00:00:00 2001 From: Orion C Date: Wed, 20 Nov 2024 13:03:22 +0100 Subject: [PATCH] Read filename from metadata --- libs/back/registry/src/s3.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/libs/back/registry/src/s3.ts b/libs/back/registry/src/s3.ts index 39e071ae21..b5a800f2d3 100644 --- a/libs/back/registry/src/s3.ts +++ b/libs/back/registry/src/s3.ts @@ -109,17 +109,23 @@ export async function getSignedUrlForUpload({ export async function getSignedUrlForDownload({ bucketName, - key + key, + fileName }: { bucketName: string; key: string; - metadata?: Record; - tags?: Record; + fileName?: string; }) { + const metadataResponse = await getFileMetadata(bucketName, key); + const metadataFileName = metadataResponse?.Metadata?.filename; + + const computedFileName = + fileName ?? metadataFileName ?? `${bucketName}_${key}`; + const command = new GetObjectCommand({ Bucket: bucketName, Key: key, - ResponseContentDisposition: `attachment; filename="${bucketName}_${key}"` + ResponseContentDisposition: `attachment; filename="${computedFileName}"` }); const signedUrl = await getSignedUrl(registryS3Client, command, {