From 57f34b9403389aba4718887f90896dfb7d5c69b6 Mon Sep 17 00:00:00 2001 From: Will Toozs Date: Tue, 9 Jul 2024 11:27:40 +0200 Subject: [PATCH] fixup: bucketName source + error if no key field --- lib/api/api.js | 8 ++++++-- lib/api/objectPost.js | 6 ++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/api/api.js b/lib/api/api.js index 74c3dc2ad0..b5c55ed03f 100644 --- a/lib/api/api.js +++ b/lib/api/api.js @@ -217,9 +217,13 @@ const api = { formDataParser.on('file', (fieldname, file, filename, encoding, mimetype) => { fileEventData = { fieldname, file, filename, encoding, mimetype }; - return next(null); + // no key field == error + if ('key' in request.formData) { + return next(null); + } + return next(errors.InvalidArgument.customizeDescription('Bucket POST must contain' + + " a field named 'key'. If it is specified, please check the order of the fields.")); }); - formDataParser.on('finish', () => { // No file field == error if (!fileEventData) { diff --git a/lib/api/objectPost.js b/lib/api/objectPost.js index 95b0db335f..eb08510ca2 100644 --- a/lib/api/objectPost.js +++ b/lib/api/objectPost.js @@ -37,14 +37,16 @@ function objectPost(authInfo, request, streamingV4Params, log, callback) { const { headers, method, + formData, + bucketName, } = request; let parsedContentLength = 0; const passThroughStream = new PassThrough(); const requestType = request.apiMethods || 'objectPost'; const valParams = { authInfo, - bucketName: request.formData.bucket, - objectKey: request.formData.key, + bucketName, + objectKey: formData.key, requestType, request, };