Next.Js 14 - AWS S3 Image Upload using API Route

  Рет қаралды 14,348

Raddy

Raddy

Күн бұрын

In this video I will guide you thru the process of creating an AWS S3 Bucket and applying public permissions so that files are available to anyone of the internet.
In the second half of the video, I'll demonstrate creating a file upload form using NextJs and the official AWS S3 Client SDK. I will use a client-side approach to create the form component and for the file uploads I will implement a backed API endpoint using Route handlers.
➡ Github: github.com/RaddyTheBrand/Next...
☕ BuyMeACoffee: www.buymeacoffee.com/RaddyThe...
Policy:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicReadGetObject",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::project-name-prod/*"
}
]
}
Discounts:
⚡ Hostinger: www.hostg.xyz/aff_c?offer_id=...
⚡ Elementor: be.elementor.com/visit/?bta=2...
Recording Equipment:
◾ Microphone: amzn.to/3uX0yvP
◾ Shotgun Mic: amzn.to/3aRsSJb
◾ Camera: amzn.to/3IMumkx
◾ Lens: amzn.to/3ARxvh8
◾ Lighting: amzn.to/3PBetj2
Computer Gear:
◾ Keyboard: amzn.to/3RCXRcC
◾ Headphones: amzn.to/3aIvskX
◾ Mouse: amzn.to/3VfVuxO
Connect with me:
◾ Website: www.raddy.dev
◾ Newsletter: www.raddy.co.uk/newsletter
Chapters:
◾ 0:00 Introduction:
◾ 0:30 S3 Bucket Setup
◾ 3:41 IAM Uuser Setup
◾ 6:14 Next.Js AWS S3 SDK + API
◾ 26:04 Next.Js Upload Form
#nextjs #aws

Пікірлер: 52
@BobBobIsSwag
@BobBobIsSwag 6 ай бұрын
Hey, please don't use the "NEXT_PUBLIC_" prefix before the environment variables because this makes them publicly available to the client browser. These env variables are only supposed to be used Server Side through Api Routes/Server Actions. This creates a security vulnerability.
@RaddyDev
@RaddyDev 6 ай бұрын
Thank you for pointing that out. I've pinned your comment so everybody is aware. I am am also trying to blur the public part 😄
@JustinTiell
@JustinTiell 6 ай бұрын
This video was amazing! I kept finding ones that almost solved the issue, but this was perfect for my needs.
@himynameisvirgil
@himynameisvirgil 5 ай бұрын
You save my life and my semester!!!!! Thank you so much for the tutorial. I read a lot but none was as clear as your tutorial.
@xovAvox
@xovAvox 5 ай бұрын
This is exactly the functionality I wanted to implement in my application, but I could never get it to work on my own. This tutorial is the only one out of many that I watched that actually worked for me! Thank you so much!
@RaddyDev
@RaddyDev 5 ай бұрын
Glad to hear that the video was helpful!
@tanmaypant8493
@tanmaypant8493 Ай бұрын
THANK YOU SOOOOO MUCH FOR THIS MASTERPIECE!! I am really looking forward for more on aws!
@saadbaig3060
@saadbaig3060 2 ай бұрын
Great Video! Thank you so much ❣
@tegasteve8195
@tegasteve8195 4 ай бұрын
Thank you so much. THis video was really helpful
@RaddyDev
@RaddyDev 4 ай бұрын
Glad it was helpful!
@anubhav5709
@anubhav5709 6 ай бұрын
Great video Hope u create more on AWS Services from nextjs
@RaddyDev
@RaddyDev 5 ай бұрын
That's the plan!
@RaddyDev
@RaddyDev 7 ай бұрын
I hope that you find the video useful.
@FipHomes
@FipHomes 4 ай бұрын
Did you make a video using server actions yet? If not, that would be very useful! Thanks, great job!
@RaddyDev
@RaddyDev 4 ай бұрын
I did: kzbin.info/www/bejne/aYXEnKF8ZtCchJI
@aogunnaike
@aogunnaike 7 ай бұрын
Thanks for this 🙏
@ruchithsamarawickrama4604
@ruchithsamarawickrama4604 19 күн бұрын
thank you , very clear
@eraybaydemir8550
@eraybaydemir8550 6 ай бұрын
my man it is very clear and good video. Thank you al lpt for your generous contribition. I loved your clear explanation and to the point statements and you have explained every little detail for us to understand completeyly keep it up buddy!! one thing I want to ask is why didnt we put headers params while writing the fecting request. I expected that we should write the classic: 'Content-Type' : 'application/json'
@RaddyDev
@RaddyDev 6 ай бұрын
I appreciate the comment. I should have done that to ensure that both client and server are in sync peaking the same language. I will update the GitHub repo, thank you
@abhishekkumar-ud7dc
@abhishekkumar-ud7dc 5 ай бұрын
It was really helpful
@Rajvirnahar
@Rajvirnahar 3 ай бұрын
Subscribed. can you do a video where you show how to add these stored images in S3 to to ur website front end?
@CaseStudyQB
@CaseStudyQB 5 ай бұрын
Great tutorial, i wish i knew how to get the final public path back through the api
@RaddyDev
@RaddyDev 5 ай бұрын
Thank you! Copy paste from another reply: You could do it manually:
@CaseStudyQB
@CaseStudyQB 5 ай бұрын
@@RaddyDev awesome! Thanks so much for the reply! I will try this when I get home
@himynameisvirgil
@himynameisvirgil 5 ай бұрын
Thanks!
@RaddyDev
@RaddyDev 5 ай бұрын
Wow that's super kind of you! That's my first super thanks, thank you! 🎉
@z1982_
@z1982_ 2 ай бұрын
Hello! The bundle size is 3.04 MB... Will it affect the performance of my next app?
6 ай бұрын
I don't get it - are You uploading image from the server? So you send image to Your server and then it sends to remote server?
@RaddyDev
@RaddyDev 6 ай бұрын
The web server acts as a middleman. A person uploads a file using a form, web server receives the file (perform any operations - ex file optimisation, checks, etc...) and then we use the AWS SDK API to send the file directly to AWS S3. In this case nothing is stored on the web server and we just use it for processing, validation, optimisation etc..
@ExtremelyDumb
@ExtremelyDumb 5 ай бұрын
Hey, I think I'm following your setup instructions line by line but can't get this working. I've updated next and node, but whenever I use ThunderClient I get a 200 response and an empty error (the 'image not uploaded' error is triggering but replacing with `error` throws a blank response). Checking AWS under my access key, it's not being successfully called. I've checked the .env.local file and copied the formatting you placed in the video and the github, and copied that same formatting. How can I further debug this, since the console and the outputs are not telling me where the code is failing?
@RaddyDev
@RaddyDev 5 ай бұрын
Could you download the code from GitHub and give it a go. Link in the description. Let me know how it goes
@injamulhaque9641
@injamulhaque9641 3 ай бұрын
the bucket policy given in the description is not working, I have added "s3:PutObject" in the Actions array then it is working, did I do it correct?
@RaddyDev
@RaddyDev 3 ай бұрын
It's not the Action, but the Resource that you need to change. You need to add your bucket name, like I did in the video. This line: "Resource": "arn:aws:s3:::your-bucket-arn-name/*"
@YashKumar-cj6gx
@YashKumar-cj6gx 6 ай бұрын
Hey can you give the code which gives us the public link on the same page of our image after uploading it to S3
@RaddyDev
@RaddyDev 6 ай бұрын
It should be in the description of the video
@ongame2264
@ongame2264 5 ай бұрын
How to get the image url or show the images to our website? I have tried using the AWS SDK Client S3 but it doesn't work. Can you give some explanation? Is there a tutorial about this? Thanks in advance🙌
@RaddyDev
@RaddyDev 5 ай бұрын
You could do it manually:
@ongame2264
@ongame2264 5 ай бұрын
Oh my gosh, this is a very nice idea! Thank you so much @@RaddyDev! 🙌
@amranmohamed377
@amranmohamed377 6 ай бұрын
How do you get the policy; you justed pasted from out no where 😅
@RaddyDev
@RaddyDev 6 ай бұрын
😁 When you Edit the Bucket policy you can click on Policy Examples or Policy Generator and create one that suits your needs. In Policy Examples you'll find a lot of good use cases which you can copy/paste and finally, you can look at the Varcel AWS S3 Image Upload example policy. They've added a few more actions: { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "s3:DeleteObject", "s3:GetObject", "s3:ListBucket", "s3:PutObject", "s3:PutObjectAcl" ], "Resource": ["arn:aws:s3:::BUCKET_NAME", "arn:aws:s3:::BUCKET_NAME/*"] } ] }
@amranmohamed377
@amranmohamed377 6 ай бұрын
@@RaddyDevThank you SOO much for your tutorial video Raddy! Please can you direct us how to do it with server actions, if you get a time tor that?
@RaddyDev
@RaddyDev 6 ай бұрын
That's how I ended up doing it on one of my website - using server actions. I could do a video on that... I am strongly considering making one
@GeisaGamer
@GeisaGamer 3 ай бұрын
Do you have a video with typescript?
@RaddyDev
@RaddyDev 3 ай бұрын
I only have JS. Maybe you could ask AI to help you out convert them
@nhanhuynh1845
@nhanhuynh1845 6 ай бұрын
hey bro, when I click to Object URL of the image after uploaded in s3, it will auto download but i just want it to show the image. How can I fix it?
@RaddyDev
@RaddyDev 6 ай бұрын
This sound like a browser setting problem to me. Can you try on another browser to see if the images open instead of download directly? It's probably a setting that you can change easily
@nhanhuynh1845
@nhanhuynh1845 6 ай бұрын
​@@RaddyDevtks I fixed it, I missed property ContentType when put command 😅
@maxmurakami-moses4728
@maxmurakami-moses4728 25 күн бұрын
Can you create a tutorial with all the privacy things turned on? I don't want anyone on the web to be able to access my files.
@RaddyDev
@RaddyDev 25 күн бұрын
You can turn the privacy ON and nobody is going to be able to access them. If you want to allow access to a specific IP, that's possible too. A good example of how to do this is provided in their documentation, which you can find near the Bucket Policy text area.
@Wannabvlogger
@Wannabvlogger 3 ай бұрын
Thank you so much for this , can we go ahead one more step and show the data already stored in aws bucket in our frontend ?? Then i can make a porn web i guess i can put all the video manuallly in s3 and then i just have to show them in frontend Pls reply
Next.Js 14 - AWS S3 File Upload using Server Actions
45:25
Upload Images Directly to S3 from Front End
18:28
Sam Meech-Ward
Рет қаралды 116 М.
СҰЛТАН СҮЛЕЙМАНДАР | bayGUYS
24:46
bayGUYS
Рет қаралды 828 М.
狼来了的故事你们听过吗?#天使 #小丑 #超人不会飞
00:42
超人不会飞
Рет қаралды 65 МЛН
Hot Ball ASMR #asmr #asmrsounds #satisfying #relaxing #satisfyingvideo
00:19
Oddly Satisfying
Рет қаралды 21 МЛН
$10,000 Every Day You Survive In The Wilderness
26:44
MrBeast
Рет қаралды 99 МЛН
Rubens Uchôa - Tua Amizade Faz Um Bem Pra Mim | Clipe Oficial
3:36
Storing Images in S3 from Node Server
39:59
Sam Meech-Ward
Рет қаралды 78 М.
Did Theo Really Fix File Uploading?
8:39
Josh tried coding
Рет қаралды 17 М.
Golang Web Server and RSS Scraper | Full Tutorial
2:49:35
Boot dev
Рет қаралды 40 М.
NodeJs How to upload Files + uploading to AWS S3 using Express, Multer
1:16:31
Sanjeev Thiyagarajan
Рет қаралды 44 М.
10 common mistakes with the Next.js App Router
20:37
Vercel
Рет қаралды 178 М.
Storing S3 Bucket Image URLs in MongoDB using Multer, NodeJS
27:57
FrontendInterviewPro
Рет қаралды 28 М.
WebRTC Crash Course
1:10:06
Hussein Nasser
Рет қаралды 218 М.
СҰЛТАН СҮЛЕЙМАНДАР | bayGUYS
24:46
bayGUYS
Рет қаралды 828 М.