tustvold commented on issue #3300: URL: https://github.com/apache/arrow-rs/issues/3300#issuecomment-1345362424
> The content-type argument is the default value if that fails. Oh I see the confusion `with_content_type_for_extension` is a method on [ClientOptions](https://docs.rs/object_store/latest/object_store/struct.ClientOptions.html) which is global for a given ObjectStore, i.e. setup once on startup, not per request. So it needs to contain all the content types the user may wish to write. So `with_content_type_for_extension` is adding a key value pair to the `HashMap`, to be used when looking up a ContentType for a given request. Similarly `with_default_content_type` is setting a default `ContentType` for if the extension is not present in the `HashMap`. > And I can populate the said HashMap from something like [here](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types). At least initially I think it is probably simpler, and less of a potentially breaking change for this feature to be opt-in, i.e. users specify specifically the extensions they wish for a `ContentType` to be specified for. So the following might work ``` let options = ClientOptions::new() .with_default_content_type("text/plain; charset=utf-8") .with_content_type_for_extension("json", "application/json") .with_content_type_for_extension("html", "text/html; charset=utf-8"); let s3 = AmazonS3Builder::new() .with_region(REGION) .with_bucket_name(BUCKET_NAME) .with_access_key_id(ACCESS_KEY_ID) .with_secret_access_key(SECRET_KEY) .with_client_options(options) .build(); // Will write with content type text s3.put(Path::from("test.txt"), "hello world".into()).await.unwrap(); // Will write with content type html s3.put(Path::from("test.html"), "<body>hello world</body>".into()).await.unwrap(); // Will write with content type json s3.put(Path::from("test.json"), "{\"hello\": \"world\"}".into()).await.unwrap(); ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
