Uploaded images get octet-stream mime type
I'm new to Supabase and I'm trying to upload an image. The uploading works fine, and I can display images as well.
I noticed in the Dashboard, the image uploaded has the wrong mime-type. How do I correct this?
Although uploading is working, I would like to restrict the bucket to specific mime types. I did that, and now uploading doesn't work at all. Presumably because the server is not sending the correct mime-type?
If I uncomment that contentType line, it still doesn't pass the correct mime type.
11 Replies
Definitely not picking up the type of file from your banner data.
What is your environment you are uploading in? If using a browser it should be able to get the file info from the file interface/blob. I would console log your extension variable and make sure it is set as that should set the mime type.
What is your environment you are uploading in? If using a browser it should be able to get the file info from the file interface/blob. I would console log your extension variable and make sure it is set as that should set the mime type.
It's a website made with Astro. The page in question is a form where someone can upload a banner (image).
The form's enctype is
multipart/form-data
This is how I get the form field:
When I console.log it right away I get this:
I rename the file to banner.png, and then I upload it.
Right now, because I added the mime-type restriction I get:
But before it would upload, just with the wrong mime-typeI have no idea about Astro and how it handles the file data.
Yes your process is not picking up the mime type if it was uploading as an octet-stream.
I also tried this:
contentType though should set it.
maybe something is going wrong with the renaming
image/png would be the content type.
I'll add another console.log
hmm interesting
it's losing the mimetype when I rename the file
OK sounds like you have a handle on it and it is not at this moment a Supabase thing.
https://supabase.com/docs/reference/javascript/storage-from-upload talks about needing contentType for some environments.
JavaScript: Upload a file | Supabase Docs
Supabase API reference for JavaScript: Upload a file
Yeah I read it, and using that, but I just didn't expect the lose the mime-type after renaming the file. But it's okay, I can figure out the rest.
Thanks a lot for helping 👍
I appreciate it