-
Notifications
You must be signed in to change notification settings - Fork 512
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: Automatically add Content-Type
based on the extension in the path (or provide an API for automatic setting)
#4902
Comments
Thank you for submitting this pull request. I understand the feature request, but I don't think auto-detection is a good approach. Perhaps we could implement a Users can use this layer like this: let op = op.layer(MimeGuessLayer::default());
op.write("x.pdf", bs).await?; <-- content-type will be `pdf`. What do you think? |
This layer could do more: detect the content_type if storage service doesn't provide it. For example, local fs doesn't store the content_type for file. We can use this layer to detect it when user call let op = op.layer(MimeGuessLayer::default().with_abc()); <-- API name need design, but it's optional.
let meta = op.stat("x.pdf").await?; <-- `meta.content_type()` will be `pdf`.
let entries = op.list("path/to/dir").await?; <-- all entries will have correct content_type. |
Wow, that's a great idea! I think it's much better than my previous design, and it's indeed more useful and flexible! This design perfectly meets my expectations and needs, so I fully approve of it. |
I see you've indicated a willingness to contribute. Given the recent design changes, are you still interested in implementing it? |
I am indeed willing to contribute, but I am still a novice in contributing to large open source projects and unsure if I can handle it well. Moreover, if we follow our newly designed concept, this feature would appear to require a significant amount of work, especially if we include the reading of file format magic headers (I'm not sure if there are any existing crates in the Rust community that can retrieve MIME information based on magic headers, and if not, we may need to create a large table). |
This is optional. We can implement the basic |
Let me take some time to read the source code first, in order to better understand the overall architecture of Layer‘s implementation. |
I have finished reading the code related to Firstly, I don't know if my understanding above is correct? |
Looks great, let's go! |
Feature Description
If I understand correctly, in the current version of OpenDAL, no matter what file we upload to the object storage, its default
Content-Type
will always beapplication/octet-stream
. If I want to modify this default behavior, I have to manually set the Content-Type myself using something likeOperator::write_with
. This is not very convenient, and it should not be the expected behavior. The expectedContent-Type
should automatically match the path extension. Of course, I can easily implement this capability at the application level usingmime_guess
myself, but I think it would be more convenient to sink this behavior into OpenDAL. Either change the default behavior ofOperator::write
directly to this, or add a method similar tocontent_type_guessed
to FutureWrite. Of course, the specific API design can be discussed further, but I believe that no matter how we choose, adding this feature will make uploading files more convenient and intuitive.Problem and Solution
Allow
Operator::write
to automatically set the correspondingContent-Type
based on the file extension in the path, or add a method toFutureWrite
to automatically set this.Additional Context
No response
Are you willing to contribute to the development of this feature?
The text was updated successfully, but these errors were encountered: