From 558e17b91df5d5d9ae1f1299a400625919f2fc80 Mon Sep 17 00:00:00 2001 From: KillianG Date: Fri, 15 Nov 2024 14:52:16 +0100 Subject: [PATCH] Fix space before and after brackets Issue: CLDSRV-570 --- .../apiUtils/object/abortMultipartUpload.js | 2 +- test.js | 106 ++++++++++++++++++ 2 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 test.js diff --git a/lib/api/apiUtils/object/abortMultipartUpload.js b/lib/api/apiUtils/object/abortMultipartUpload.js index f49d861054..c5928b7229 100644 --- a/lib/api/apiUtils/object/abortMultipartUpload.js +++ b/lib/api/apiUtils/object/abortMultipartUpload.js @@ -128,7 +128,7 @@ function abortMultipartUpload(authInfo, bucketName, objectKey, uploadId, log, uploadId, versionId: objectMD.versionId }); - return metadata.deleteObjectMD(bucketName, objectKey, {versionId: objectMD.versionId}, log, err => { + return metadata.deleteObjectMD(bucketName, objectKey, { versionId: objectMD.versionId }, log, err => { if (err) { log.error('error deleting object metadata', { error: err }); } diff --git a/test.js b/test.js new file mode 100644 index 0000000000..c51456b1c2 --- /dev/null +++ b/test.js @@ -0,0 +1,106 @@ +const AWS = require('aws-sdk'); +const s3 = new AWS.S3({ + accessKeyId: 'UWB6VWIZPHI19HG74PPD', + secretAccessKey: 'HOO7agVIZ+mUrXJznyo7eT/2G1tsZrIRQ3WeP8vv', + endpoint: 'http://s3.workloadplane.pra.scality.local', + s3ForcePathStyle: true, + signatureVersion: 'v4', + maxRetries: 0, +}); +const bucket = 'mpuver'; +const key = 'test-object'; +const partSize = 5 * 1024 * 1024; +const numParts = 10; +let uploadID; +let completedParts +async function createAndUploadMPU() { + try { + const createMPUResponse = await s3.createMultipartUpload({ Bucket: bucket, Key: key }).promise(); + const uploadId = createMPUResponse.UploadId; + uploadID = uploadId; + console.log('Multipart upload initiated:', uploadId); + let parts = []; + for (let i = 1; i <= numParts; i++) { + const partData = Buffer.alloc(partSize, `Part-${i}`); + const uploadPartResponse = await s3.uploadPart({ + Bucket: bucket, + Key: key, + PartNumber: i, + UploadId: uploadId, + Body: partData + }).promise(); + parts.push({ ETag: uploadPartResponse.ETag, PartNumber: i }); + console.log(`Uploaded part ${i}`); + } + completedParts = parts.slice(0, numParts - 1); + await s3.completeMultipartUpload({ + Bucket: bucket, + Key: key, + UploadId: uploadId, + MultipartUpload: { Parts: completedParts } + }).promise(); + console.log('Multipart upload completed with parts', completedParts); + } catch (error) { + console.error('Error in multipart upload:', error); + console.log("===============================================") + try { + console.log("uploadID", uploadID) + } catch (error) { + console.error('Error in aborting multipart upload:', error); + } + } +} + +async function abortMPU(uploadID) { + try { + await s3.abortMultipartUpload({ + Bucket: bucket, + Key: key, + UploadId: uploadID + }).promise(); + console.log('Multipart upload aborted'); + } catch (error) { + console.error('Error in aborting multipart upload:', error); + } +} + +async function createBucket() { + try { + await s3.createBucket({ Bucket: bucket }).promise(); + console.log('Bucket created:', bucket); + } catch (error) { + console.error('Error in creating bucket:', error); + } +} + +async function getObject() { + try { + const object = await s3.headObject({ Bucket: bucket, Key: key }).promise(); + console.log('Object retrieved:', object); + } catch (error) { + console.log('Error in getting object:', error); + } +} + +async function completeMPU() { + try { + await s3.completeMultipartUpload({ + Bucket: bucket, + Key: key, + UploadId: uploadID, + MultipartUpload: { Parts: completedParts } + }).promise(); + console.log('Multipart upload completed with parts', completedParts); + } catch (error) { + console.error('Error in completing multipart upload:', error); + } +} + +async function main() { + await createAndUploadMPU(); + console.log(">>>>>>>>>>>>>>>>>>>") + await getObject(); + console.log("<<<<<<<<<") +} + +main() \ No newline at end of file