Image uploads have the wrong MIME type
funwithtriangles opened this issue · comments
Hey @funwithtriangles,
Thanks for reporting this - we actually have an options which lets you set the mime-type. I haven't tested in a while but you may wish to give that a try - https://github.com/supabase-community/storage-py/blob/main/storage3/_async/file_api.py#LL225C15-L225C15
I'll take a deeper look when a slot frees up.
Hi @J0 and @funwithtriangles
Just wondering if either of you managed to get this to work in a Python environment?
We're also experiencing difficulties writing images to bucket - MIME type is automatically text/plain (but downloads as a workable image) - but specifying using the Content-Type header produces correct MIME type but is unopenable upon download. In both instances, preview isn't working - which is the big thing for us (along with transformation options).
Upload is here (in case it's just an incorrect use of the parameter):
result_1 = supabase.storage.from_([BUCKET]).upload( "[FILE_NAME].png", "PNG_transparency_demonstration_1.png", file_options={"Content-Type":"image/png"})
Demo image is just a .png image that we've gotten elsewhere (just so we know it's not an encoding issue on our end..!) and saved in the local directory.
Both occur when working with images picked up from disk and from memory buffer.
Any advice would be amazing - my suspicion is that some metadata is being dropped upon upload or download.
Lydia
I slept on it, looked at it again this morning, and looked at the definition again - and solved it. It's a silly mistake on my end, but for anyone who is looking for a similar solution:
If you're new to HTTP headers (like me), you'll see them commonly written in camel case. However, for the header to work correctly, please use all lower case. I.e change Content-Type
to content-type
.
For devs - there's no error catching on the upload end to inform the user, so it errs silently. Just an FYI, if you wanted to add in a little cleaning.
I've opened #100 hopefully that makes it clear for future users.
After that's merged you should be getting intellisense in your IDE too like so:
#100 has been merged and an example for setting the mime type properly in .upload
has been added to the README. If anyone has any ideas to improve DX on this further please ping me and comment here 😄
Thank you!