From bd0c4ceae20a39a33fea01addc865b8b5bdd63fa Mon Sep 17 00:00:00 2001 From: Patrick Fic Date: Wed, 25 Jun 2025 16:32:47 -0700 Subject: [PATCH] IO-3281 Resolve key issue for downloads. --- server/media/imgproxy-media.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/server/media/imgproxy-media.js b/server/media/imgproxy-media.js index 55d88f938..46a8dd840 100644 --- a/server/media/imgproxy-media.js +++ b/server/media/imgproxy-media.js @@ -103,13 +103,7 @@ const getThumbnailUrls = async (req, res) => { /////< base 64 URL encoded to image path> //When working with documents from Cloudinary, the URL does not include the extension. - let key; - - if (/\.[^/.]+$/.test(document.key)) { - key = document.key; - } else { - key = `${document.key}.${document.extension.toLowerCase()}`; - } + let key = keyStandardize(document) // Build the S3 path to the object. const fullS3Path = `s3://${imgproxyDestinationBucket}/${key}`; const base64UrlEncodedKeyString = base64UrlEncode(fullS3Path); @@ -205,7 +199,7 @@ const downloadFiles = async (req, res) => { try { for (const doc of data.documents) { - const key = doc.key; + let key = keyStandardize(doc) let response; try { response = await s3client.send( @@ -388,6 +382,15 @@ const moveFiles = async (req, res) => { } }; +const keyStandardize = (doc) => { + if (/\.[^/.]+$/.test(doc.key)) { + return doc.key; + } else { + return `${doc.key}.${doc.extension.toLowerCase()}`; + } +}; + + module.exports = { generateSignedUploadUrls, getThumbnailUrls,