Image transformation fails on some image formats
Svarto opened this issue · 11 comments
png
and jpg
images are supported, the issue is that you are sending an invalid mime type (which v1 didn't check). Please, send a valid mime type and it should work just fine.
For more info you can refer to the following url: https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types
@dbarrosop thank you for the response!
I am not sending any mime type, I am just navigating to an URL that serves an image stored in my Nhost storage. If I understand you correctly, it means that Nhost storage does not validate the mime type of the images OR just passes on incorrect mime types to the transformation function in the storage.
Can you please help how to manage this when migrating from v1, how can I correct the mime types of the images I have on v2 storage?
Would you mind sharing an image that isn't working so I can test myself? Feel free to share here (if they can be shared) or ping me on discord if you prefer to do it privately.
Also, would you mind giving more details on how those images where uploaded? Did you do it yourself with code? (would you mind sharing?) or via the storage UI?
@dbarrosop of course, here is an image: https://rklttyqwdzlikrmxlvpg.storage.eu-central-1.nhost.run/v1/files/13dca9dd-ea3d-48d8-9d63-a80f635191a3
I think that the issue we are running into here is that on mobile when picking an image from the camera roll or taking an image, the mime type is not provided. So it has to be generated, I am generating it by taking the type (which returns image or photo, depending on OS / phone) and then the ending of the file (which can be jpg, jpeg or png depending on OS and phone). These generated mime types create some that are aligning to official standards, and others that are not.
code:
type: `${image.type}/${image.uri.substring(
image.uri.lastIndexOf(".") + 1
)}`
I can standardize it in my frontend (there are some good mime JS libraries that read the mime type from the file name), with that said it won't fix my 1000+ images that are already uploaded to nhost in v1...
By default the storage service will figure out the mime type and set it correctly so unless you have some specific need to compute it yourself I'd recommend just letting the service do it itself. I tried to upload your picture using our files UI (which doesn't bother with the MIME type) and it worked as expected:
Also, not sure if you are writing to the database yourself, but there is no need for it (and actually I would discourage you from doing it), you can just upload the file and everything should be filled for you. Reading is fine though.
@dbarrosop is it possible that this changed since 16th March? When I upload a mislabeled image now (i.e. content-type image/jpg) it gets automatically stored in storage with a correct mime-type image/jpeg?
I will need to remigrate all my images, but that can be done with minor modifications of my previous migrate script.
don't recall the exact date (I could check) but we release around April a rewritten version of hasura-storage. Previous version handled mimetypes when uploading this way too though.
The announcement was here: https://nhost.io/blog/hasura-storage-in-go-5x-performance-increase-and-40-percent-less-ram
@dbarrosop this seems to be a none issue now, as when I run my migration script and re-upload images they are automatically identified as the correct mimetype even when taken "as-is" from nhost v1. Thanks a lot for the help!
no worries, glad the issue was sorted out :)