Important: This documentation is about an older version. It's relevant only to the release noted, many of the features and functions have been updated or replaced. Please view the current version.
Specifies presentational information for the object. For more information, see RFC 6266.
contentEncoding
string (optional)
Specifies what content encodings have been applied to the object and thus what decoding mechanisms must be applied to obtain the media-type referenced by the Content-Type header field. For more information, see RFC 2616.
contentLength
number (optional)
Size of the body in bytes. This parameter is useful when the size of the body cannot be determined automatically.
contentMD5
string (optional)
The base64-encoded 128-bit MD5 digest of the message (without the headers) according to RFC 1864. This header can be used as a message integrity check to verify that the received message is identical to the message that was sent.
contentType
string (optional)
A standard MIME type describing the format of the object data. For more information, see RFC 2616.
Returns
Type
Description
Promise<void>
A Promise that fulfills when the object has been uploaded to the S3 bucket.
Example
JavaScript
import{ AWSConfig, S3Client }from'https://jslib.k6.io/aws/0.11.0/s3.js';const awsConfig =newAWSConfig({region: __ENV.AWS_REGION,accessKeyId: __ENV.AWS_ACCESS_KEY_ID,secretAccessKey: __ENV.AWS_SECRET_ACCESS_KEY,});const s3 =newS3Client(awsConfig);const testBucketName ='test-jslib-aws';const testFileKey ='bonjour.txt';const testFile =open('./bonjour.txt','r');exportdefaultasyncfunction(){// Let's upload our test file to the bucketawait s3.putObject(testBucketName, testFileKey, testFile,{contentType:'text/plain',contentLength: testFile.length,});// And let's redownload it to verify it's correctconst obj =await s3.getObject(testBucketName, testFileKey);
console.log(JSON.stringify(obj));}
A k6 script that will upload an object to a S3 bucket