-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix multipart upload - move query parameters to HTTP request query ob…
…ject (#47) * minor correction of the uploads parameter * fixed protocol to be `this.scheme` * add @oleiade's example
- Loading branch information
Showing
13 changed files
with
99 additions
and
26 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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,66 @@ | ||
import crypto from 'k6/crypto' | ||
import exec from 'k6/execution' | ||
|
||
import { AWSConfig, S3Client } from '../build/s3.js' | ||
|
||
const awsConfig = new AWSConfig({ | ||
region: __ENV.AWS_REGION, | ||
accessKeyId: __ENV.AWS_ACCESS_KEY_ID, | ||
secretAccessKey: __ENV.AWS_SECRET_ACCESS_KEY, | ||
sessionToken: __ENV.AWS_SESSION_TOKEN, | ||
}) | ||
|
||
|
||
const s3 = new S3Client(awsConfig) | ||
|
||
const testBucketName = 'test-jslib-aws' | ||
const testFileKey = 'multipart.txt' | ||
|
||
export default function () { | ||
// List the buckets the AWS authentication configuration | ||
// gives us access to. | ||
const buckets = s3.listBuckets() | ||
|
||
// If our test bucket does not exist, abort the execution. | ||
if (buckets.filter((b) => b.name === testBucketName).length == 0) { | ||
exec.test.abort() | ||
} | ||
|
||
// Produce random bytes to upload of size ~12MB, that | ||
// we will upload in two 6MB parts. This is done as the | ||
// minimum part size supported by S3 is 5MB. | ||
const bigFile = crypto.randomBytes(12 * 1024 * 1024) | ||
|
||
// Initialize a multipart upload | ||
const multipartUpload = s3.createMultipartUpload(testBucketName, testFileKey) | ||
|
||
// Upload the first part | ||
const firstPartData = bigFile.slice(0, 6 * 1024 * 1024) | ||
const firstPart = s3.uploadPart( | ||
testBucketName, | ||
testFileKey, | ||
multipartUpload.uploadId, | ||
1, | ||
firstPartData | ||
) | ||
|
||
// Upload the second part | ||
const secondPartData = bigFile.slice(6 * 1024 * 1024, 12 * 1024 * 1024) | ||
const secondPart = s3.uploadPart( | ||
testBucketName, | ||
testFileKey, | ||
multipartUpload.uploadId, | ||
2, | ||
secondPartData | ||
) | ||
|
||
// Complete the multipart upload | ||
s3.completeMultipartUpload(testBucketName, testFileKey, multipartUpload.uploadId, [ | ||
firstPart, | ||
secondPart, | ||
]) | ||
|
||
// Let's redownload it verify it's correct, and delete it | ||
const obj = s3.getObject(testBucketName, testFileKey) | ||
s3.deleteObject(testBucketName, testFileKey) | ||
} |
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