From 58e2e539f82950151c2b8c1346d6f224616d47ee Mon Sep 17 00:00:00 2001 From: ZGaetano Date: Tue, 19 May 2026 00:08:13 -0400 Subject: [PATCH] fix(upload): scope original S3 keys under assetId to prevent collisions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Both /init and /simple were keying originals as `originals/${projectId}/${filename}`. Two uploads of the same filename into the same project would share a key — the second upload would silently overwrite the first file in S3 while both assets remained in the DB with the same original_s3_key. Changed to `originals/${assetId}/${filename}` (matching the proxies/ convention) so every asset has its own unique S3 prefix. --- services/mam-api/src/routes/upload.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/services/mam-api/src/routes/upload.js b/services/mam-api/src/routes/upload.js index ae1d46f..c987f4d 100644 --- a/services/mam-api/src/routes/upload.js +++ b/services/mam-api/src/routes/upload.js @@ -103,7 +103,8 @@ router.post('/init', async (req, res, next) => { } const assetId = uuidv4(); - const s3Key = `originals/${projectId}/${filename}`; + // Include assetId in the key so same-named files in a project never collide + const s3Key = `originals/${assetId}/${filename}`; const tagsArray = tags ? (Array.isArray(tags) ? tags : [tags]) : []; await pool.query( @@ -259,7 +260,8 @@ router.post('/simple', upload.single('file'), async (req, res, next) => { } const assetId = uuidv4(); - const s3Key = `originals/${projectId}/${filename}`; + // Include assetId in the key so same-named files in a project never collide + const s3Key = `originals/${assetId}/${filename}`; const mimeType = contentType || req.file.mimetype; const tagsArray = tags ? (Array.isArray(tags) ? tags : [tags]) : [];