Next.js Discord

Discord Forum

Best way to store image in databse w/ nextjs ?

Answered
Savannah posted this in #help-forum
Open in Discord
SavannahOP
Hi guys, i would to know what's the best way/method to store image in database w/nextjs using mysql2 ? At the moment, i'm thinking of doing it natively by storing images with a blob type, but i'd still like to know if there isn't something more optimized/better to use to do it ?
Answered by B33fb0n3
I like to use a object storage like r2 or s3 or whatever to store the images and they give me a storage key. Then I can save this storage key as plain text inside my database. When I want to access that image again, I just fetch the storage key and get it from my storage
View full answer

23 Replies

@Savannah Hi guys, i would to know what's the best way/method to store image in database w/nextjs using mysql2 ? At the moment, i'm thinking of doing it natively by storing images with a blob type, but i'd still like to know if there isn't something more optimized/better to use to do it ?
I like to use a object storage like r2 or s3 or whatever to store the images and they give me a storage key. Then I can save this storage key as plain text inside my database. When I want to access that image again, I just fetch the storage key and get it from my storage
Answer
@Savannah Does this video explain what you ere talking about ? (s3) : https://www.youtube.com/watch?v=inzUefvk2RE
yea, but that's only the upload. You also need to store they key in your database. This is the key, that you need to save: (see attached)
The key can be anything you want
@B33fb0n3 The key can be anything you want
SavannahOP
Okayy, thanks a lot brother
@Savannah Okayy, thanks a lot brother
happy to help. Please mark solution
@B33fb0n3 happy to help. Please mark solution
SavannahOP
👍
ping me in future threads, if you need more help with that topic 🙂
@B33fb0n3 ping me in future threads, if you need more help with that topic 🙂
SavannahOP
Yeah sure, thanks my g
SavannahOP
Btw, is aws s3 paid ? @B33fb0n3
@Savannah Btw, is aws s3 paid ? <@301376057326567425>
yes and no. Yes, because it is paid. But no, because it has a huge free plan
@B33fb0n3 yes and no. Yes, because it is paid. But no, because it has a huge free plan
SavannahOP
Erf, they're askin me my credit card to sign in x)
yea xD
@B33fb0n3 yea xD
SavannahOP
fk, there is not a way to do that but free ? xD
I'm creating a web application for my first high school internship but I don't think they've budgeted any extra costs for that tbh xD
no xD
Try creating an alarm, so you don't get charged
@B33fb0n3 no xD Try creating an alarm, so you don't get charged
SavannahOP
what's an alarm ?
@Savannah I'm creating a web application for my first high school internship but I don't think they've budgeted any extra costs for that tbh xD
you won't be charges, when you keep the usage low. Take a look at their free plan
@Savannah what's an alarm ?
an alarm is like a budget. It will send you a message or directly stopp the service or ... whatever you enter
This package helps streamline file uploading to s3 and it integrates with your db