uploadPart
Open source
uploadPart
S3Client.uploadPart
uploads a part to multipart upload in a bucket.
Parameter | Type | Description |
---|---|---|
bucketName | string | Name of the bucket to upload the object to. |
objectKey | string | Name of the object to upload. |
uploadId | string | UploadId of the multipart upload. |
partNumber | number | The Part number of the Part to upload. |
data | string | ArrayBuffer | Content of the part to upload. |
Returns
Example
JavaScript
import crypto from 'k6/crypto';
import exec from 'k6/execution';
import {
AWSConfig,
S3Client,
} from 'https://jslib.k6.io/aws/0.12.3/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 async function () {
// 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 = await s3.createMultipartUpload(testBucketName, testFileKey);
// Upload the first part
const firstPartData = bigFile.slice(0, 6 * 1024 * 1024);
const firstPart = await s3.uploadPart(
testBucketName,
testFileKey,
multipartUpload.uploadId,
1,
firstPartData
);
// Upload the second part
const secondPartData = bigFile.slice(6 * 1024 * 1024, 12 * 1024 * 1024);
const secondPart = await s3.uploadPart(
testBucketName,
testFileKey,
multipartUpload.uploadId,
2,
secondPartData
);
// Complete the multipart upload
await s3.completeMultipartUpload(testBucketName, testFileKey, multipartUpload.uploadId, [
firstPart,
secondPart,
]);
// Let's redownload it verify it's correct, and delete it
const obj = await s3.getObject(testBucketName, testFileKey);
await s3.deleteObject(testBucketName, testFileKey);
}
A k6 script that will upload a part in a multipart upload to an S3 bucket
Was this page helpful?
Related documentation
Related resources from Grafana Labs
Additional helpful documentation, links, and articles:
08 May

k6 1.0: How this long-awaited major release makes it easier to get started with testing
Grafana k6 v1.0 is here! k6 contributors will demonstrate features in the open source load testing tool, such as native extensibility (no more xk6 workarounds); the OpenAPI converter to streamline and automate the creation of TypeScript-based tests; and k6 Studio, a desktop application that simplifies performance testing for everyone.
60 min

Performance testing and observability in Grafana Cloud
In this webinar, learn how Grafana Cloud k6 offers you the best developer experience for performance testing.
60 min

User-centered observability: load testing, real user monitoring, and synthetics
Learn how to use load testing, synthetic monitoring, and real user monitoring (RUM) to understand end users' experience of your apps. Watch on demand.