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
kian
kian2y ago
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
Isaac McFadyen
mime_guess MeowHeartCloudflare 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
nomaxx117
nomaxx117OP2y ago
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
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
kian
kian2y ago
I wonder if you can use Transform Rules for this meowthinking
kian
kian2y ago
kian
kian2y ago
Nope meowangery
Want results from more Discord servers?
Add your server