MooseSaid's avatar

Best practice for storing products images

I'm building E-commerce website where every product can have multiple images. I'm looking for an expert opinion on how to store those images? I was thinking of making the product model 'hasMany' images and Images table will contain all images for all products and I will fetch the ones I need according to the product ID.

1- Is there a better way to do it? 2- Do you recommend saving my images to a separate server like AWS and keep my site host small? I mean, is it bad to save them in a relative path within my project?

0 likes
3 replies
tykus's avatar

You're on the right track there, but consider using Spatie's MediaLibrary package - it will take care of many of these decisions for you

1 like
MooseSaid's avatar

@tykus I will definitely read more about it, thanks! Do you recommend saving my images to a separate server like AWS and keep my site host small? I mean, is it bad to save them in a relative path within my project?

tykus's avatar
tykus
Best Answer
Level 104

@MooseSaid

Do you recommend saving my images to a separate server like AWS and keep my site host small? I mean, is it bad to save them in a relative path within my project?

it depends; you absolutely can get by without S3 or similar if the ecommerce store is relatively small - most VPS will provide you with sufficient storage; but it also carries the risk that you have no redundancy/backups if the server should be lost (it can happen!). Up to you to assess the risk vs. the cost.

1 like

Please or to participate in this conversation.