-
Notifications
You must be signed in to change notification settings - Fork 241
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue: CLDSRV-570
- Loading branch information
Showing
2 changed files
with
107 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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("===============================================") | ||
Check failure on line 45 in test.js GitHub Actions / linting-coverage
Check warning on line 45 in test.js GitHub Actions / linting-coverage
|
||
try { | ||
console.log("uploadID", uploadID) | ||
Check failure on line 47 in test.js GitHub Actions / linting-coverage
Check warning on line 47 in test.js GitHub Actions / linting-coverage
|
||
} 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() |