Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for downloading binary files using S3Client.getObject #113

Merged
merged 2 commits into from
Jul 31, 2024

Conversation

oleiade
Copy link
Member

@oleiade oleiade commented Jul 30, 2024

What

This Pull Request adds support for downloading binary S3 objects using the getObject operation to address #105 and supersede #107.

We wanted to get this done, and as the initial contributor did not appear to have the capacity to switch to the proposed design, we took the liberty to do it.

How

This PR adds an additionalHeaders parameter to S3Client.getObject. The operation additionally receives support for the Accept header. When the header is provided with the value application/octet-stream, the operation will treat the response as binary content and return an ArrayBuffer.

We decided to opt for the header approach, as it doesn't leak nor depend on k6 interfaces and adopts a standard HTTP behavior, indicating to the server the type of content we expect in return through the Accept header.

Example

// ...

export default async function () {
    await s3.getObject(testBucketName, testFileKey, {
        Accept: 'application/octet-stream',
    })
    
    // ...
}

@oleiade oleiade added the enhancement New feature or request label Jul 30, 2024
@oleiade oleiade self-assigned this Jul 30, 2024
@oleiade oleiade requested a review from a team as a code owner July 30, 2024 12:38
@oleiade oleiade requested review from codebien and joanlopez and removed request for a team July 30, 2024 12:38
@oleiade
Copy link
Member Author

oleiade commented Jul 30, 2024

For your attention @KOConchobhair 🙇🏻

This commit adds an `additionalHeaders` parameter to S3Client.getObject.
The operation additionally receives support for the `Accept` header.
When the header is provided with the value `application/octet-stream`
the operation will, as a result, treat the response as binary content
and return an ArrayBuffer.

We decided to opt for the header approach, as it doesn't leak nor depend
on k6 interfaces, and adopts a standard HTTP behavior, indicating to
the server the type of content we expect in return, through the Accept
header.
@oleiade oleiade force-pushed the s3-getobject-binary-support branch from 7fecb55 to 5588da9 Compare July 30, 2024 12:46
@oleiade oleiade merged commit b312325 into main Jul 31, 2024
3 checks passed
@oleiade oleiade deleted the s3-getobject-binary-support branch July 31, 2024 08:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants