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
![MeowHeartCloudflare](https://cdn.discordapp.com/emojis/897193652089155645.png)
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•16mo ago
Message Not Public
Sign In & Join Server To View
I wonder if you can use Transform Rules for this ![meowthinking](https://cdn.discordapp.com/emojis/350680941804388352.png)
![meowthinking](https://cdn.discordapp.com/emojis/350680941804388352.png)
![](https://cdn.answeroverflow.com/1116709067780522054/image.png)
Nope ![meowangery](https://cdn.discordapp.com/emojis/498258751581716497.png)
![meowangery](https://cdn.discordapp.com/emojis/498258751581716497.png)