Guess content type from path
Hello, I'm looking to serve data from R2 via workers. I'm used to Rust, and have used https://docs.rs/mime_guess/latest/mime_guess/ in the past to "guess" the mime type for a piece of content based on the path given.
What's the easiest way to do this with workers?
mime_guess - Rust
Guessing of MIME types by file extension.
7 Replies
Ideally the type would be stored with the object in R2 as httpMetadata so you can retrieve it - otherwise I guess a mime DB (like that) is the only way
mime_guess yeah - what kian said. There is a library that works with Workers I've used, but ideally on upload you set the proper content type and then it stores it alongside the object in the metadata
this did the trick: https://www.npmjs.com/package/mime-types
npm
mime-types
The ultimate javascript content-type utility.. Latest version: 2.1.35, last published: a year ago. Start using mime-types in your project by running
npm i mime-types
. There are 5547 other projects in the npm registry using mime-types.Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
I wonder if you can use Transform Rules for this
Nope