Low quantity image storage
Hi, I’m creating a shop backend in Go with MongoDB as a database and I need to store product images for a relatively low quantity of products. After looking around, I wasn’t sure what would be the best option to store these images. I could either use GridFS in MongoDB, Cloudflare R2 or Cloudflare images. CF images seems like it’ll be cheep but I’m unsure if it’s worth adding the complexity of another service when MongoDB can store images already. There is also the concern that there won’t be many products (probably under 50) so that plays in to things too. But, CF images does do optimisation for me so that’s a plus.
I’d love to hear your opinions on what way I should go!
7 Replies
you can try uploadthing, which has a rest api, and you can get an url for the images directly from there
or use an s3 bucket or something else that's cheap/free
but don't use the database: just because you can doesn't mean you should
what you can do, for the database, is store a VERY VERY VERY VERY low resolution of the image, and then render it as the background of the images that didn't load yet
im talking about 2kb per image, maximum
you then use the url you have from the s3 bucket or whatever service you have that manages your files, and that's the url that you use for the src
this will fake progressive loading, the website won't look like it has a hole there until the image loads and your layout won't suffer
storing images in the database is like storing sticks and stones in a briefcase, alongside your important documents
I see, thanks! If I used something like s3 then how could I do image resizing/optimisation?
you can do that before putting in the bucket
you can do it in the browser, with a canvas
or you can use imagemagick or something to do it in the server
or you can look for ways to do it in the bucket or something
you can have an aws lambda that does that step for you
aws has an article about this, where they explain how you can have it done dynamically
Interesting. Thanks for the search terms! 😆
you're welcome
Ah, I’m using Go on the backend so that isn’t an option for me