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

new feature: Add content_encoding option to operator.writer_with #5378

Open
1 task
adayoung opened this issue Dec 1, 2024 · 0 comments
Open
1 task

new feature: Add content_encoding option to operator.writer_with #5378

adayoung opened this issue Dec 1, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@adayoung
Copy link

adayoung commented Dec 1, 2024

Feature Description

When uploading objects to S3, it's possible to specify a content-encoding attribute which is currently not possible with the operator.writer_with method. The content-encoding attribute is important because compressed files uploaded to a (public) S3 bucket wouldn't correctly decompress on the browser without it.

Here's what the AWS SDK method looks like: https://docs.rs/aws-sdk-s3/latest/aws_sdk_s3/operation/put_object/builders/struct.PutObjectFluentBuilder.html#method.content_encoding

Problem and Solution

Suppose a brotli compressed css file is uploaded to S3. Without the content-encoding header, the browser wouldn't know how to decompress it before attempting to use it. The content-type header alone does not make it possible to guess how to decode a compressed file.

I imagine a content_encoding method to the writer_with method of the operator should help:

use opendal::services::S3;
use opendal::Operator;
use std::env;

let s3_region = env::var("AWS_REGION").unwrap();
let s3_endpoint = env::var("AWS_ENDPOINT_URL").unwrap();
let s3_access_key_id = env::var("AWS_ACCESS_KEY_ID").unwrap();
let s3_secret_access_key = env::var("AWS_SECRET_ACCESS_KEY").unwrap();
let bucket = "test";
let key = "styles.css.br"; // brotli compressed stylesheet
let content = get_content_from_somewhere(); // puts Vec<u8> into the content variable

let builder = S3::default()
    .bucket(bucket)
    .region(&s3_region)
    .endpoint(&s3_endpoint)
    .access_key_id(&s3_access_key_id)
    .secret_access_key(&s3_secret_access_key);

let op = Operator::new(builder)?.finish();
let mut writer = op.writer_with(key).content_type("text/css").content_encoding("br").await?;
writer.write(content).await?;
writer.close().await?;

Additional Context

No response

Are you willing to contribute to the development of this feature?

  • Yes, I am willing to contribute to the development of this feature.
@adayoung adayoung added the enhancement New feature or request label Dec 1, 2024
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

No branches or pull requests

1 participant