Upload Images with React & Node JS to AWS S3

Sdílet
Vložit
  • čas přidán 27. 07. 2024
  • In this video you'll learn how to create a responsive user interface using React and Chakra UI, and a Node JS backend that handles image uploads. You'll also learn how to store and retrieve images from AWS S3.
    UPDATED - After making this video, I realized that using a presigned URL for uploading an image is a much better approach, since the image will be uploaded directly to S3 (instead of to our API, which then sends it to S3). With this approach, a new endpoint needs to be created to generate a presigned url for PutObject(), and return that to the frontend. Then the frontend will upload the image using that URL instead of hitting our API.
    Additionally, instead using presigned URLs to view images, a Cloudfront cache should be set up (with our S3 bucket as the origin). That way you will get the benefits of using a CDN (reduced latency, cost, etc).
    Starting Files: github.com/nikitapryymak/reac...
    Finished Files: github.com/nikitapryymak/reac...
    Setup AWS Credentials:
    docs.aws.amazon.com/cli/lates...
    AWS S3 SDK: docs.aws.amazon.com/AWSJavaSc...
    0:00 Intro
    0:42 React Upload Image Button
    13:44 API - Image Upload Endpoint
    16:34 AWS S3 Bucket
    17:12 AWS SDK
    24:20 React - Fetching Images
    28:17 AWS Presigned URLs
    36:56 React Image Components
    39:09 Trigger Image Refetching
    41:09 Sort AWS S3 Files
    Github: github.com/nikitapryymak
    Support Me: www.buymeacoffee.com/nikitadev
    Contact Me: nikitadev292@gmail.com
    #react #aws #nodejs
  • Věda a technologie

Komentáře • 42

  • @luizsoares4847
    @luizsoares4847 Před rokem +5

    10 secs into the video and I'm amazed by the design. Simple but so beautiful. Well, time watch the rest of the video

  • @jamesleakos7119
    @jamesleakos7119 Před rokem +1

    This was fantastic, thank you. I was able to get uploading and downloading working in my own app!

  • @hoangchu2846
    @hoangchu2846 Před 4 dny +2

    Great video but you used a lot of extensions that automate import and stuff from which I couldn't follow your code

  • @luizsoares4847
    @luizsoares4847 Před rokem +2

    Your video helped a lot. Managed to implement it on my app and it works wonderfully. I am trying to change it a bit so I can upload multiple files. I believe I don't need to send the files in a loop 1 by 1. Can you tell me if I have to change the Body property on the command? Thank you very much.

  • @alphacentauri8035
    @alphacentauri8035 Před 8 měsíci

    Wow, i was looking all day on how to fetch the images back, finally found good tutorial!

  • @regilearn2138
    @regilearn2138 Před měsícem +1

    wow, Would appreciate if you can tech us how to add Lambda function for this

  • @poiseandtriumph
    @poiseandtriumph Před dnem

    Why still use axios when you can use fetch?

  • @fiddler-dv4or
    @fiddler-dv4or Před rokem +1

    Great video! Thank you! Do I have to use a BE server to load and query the S3 bucket? Can I save a hope by do this on the client?

    • @nikita-dev
      @nikita-dev  Před rokem +3

      Yes, a backend server is necessary (at least in this scenario) because you need to securely use AWS credentials to access the S3 bucket, and you wouldn't want to expose the credentials to the browser.

  • @VoixDeLaNation
    @VoixDeLaNation Před rokem

    How do you do this but using Websockets ?

  • @maheshraut8335
    @maheshraut8335 Před rokem

    I have done store deta in s3 bucket by the documentation but after that i want to make gallery like you for that get objects from bucket to my react app i want. For that i saw your full video but i cant do that because i dont know Axios, fletch how you uesd that can you help me....for retrive deta and display gallery in web app

  • @BruceKomesu
    @BruceKomesu Před rokem +1

    Thanks for the video! really good!
    How are you opening the backend terminal on 16:08?

    • @nikita-dev
      @nikita-dev  Před rokem

      I had a VS Code terminal open and I split the pane, and then navigated to the “frontend” folder and the left side, and the “backend” folder on the right side. once in the backend directory, I just ran “npm run dev”

  • @yashvadaria7043
    @yashvadaria7043 Před rokem

    I am facing some memeory leak from this approach when hosted on EC2.

  • @antonellagiovannetti992
    @antonellagiovannetti992 Před rokem +4

    Hello, thank you for your excellent video. I'm following your step by step tutorial and I have a problem, when I upload my image it doesn't save in s3. Here is my error: CredentialsProviderError: Could not load credentials from any providers. Thank you very much for your answer.

    • @nikita-dev
      @nikita-dev  Před rokem +1

      It seems like the SDK is not grabbing the credentials from your machine. Have you installed the AWS CLI and set up an AWS profile (with credentials) on your machine (by running the "aws configure" command)?
      To check if you have the CLI installed, run "aws --version"
      Here are the steps in case you haven't:
      Install the AWS CLI: docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html
      Configure AWS Credentials on Your Machine: docs.aws.amazon.com/cli/latest/userguide/getting-started-quickstart.html

    • @antonellagiovannetti992
      @antonellagiovannetti992 Před rokem +1

      @@nikita-dev
      Thank you very much it works!!

  • @mjftw9473
    @mjftw9473 Před 10 měsíci

    Thank God man, you saved me 🙏

  • @pawefojt8757
    @pawefojt8757 Před rokem

    Very nice video, now I can add new pictures and display it in frontend. But how to delete that pictures from aws s3?

    • @nikita-dev
      @nikita-dev  Před rokem +1

      you would have to call the DeleteObjectCommand from the SDK: docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-s3/classes/deleteobjectcommand.html
      You can also delete them manually through the AWS Console

  • @Angarag9z
    @Angarag9z Před rokem +2

    how long the images will be stored in the memory storage? do they are automatically cleared from memory storage. if not, than it will increase the load on the server.

    • @nikita-dev
      @nikita-dev  Před rokem

      The images are removed from memory as soon as the request is finished. However, if your application is storing very large files (or many small files in a short amount of time), you may run into memory issues. To help prevent that, you can set limits on the file size in the multer config

    • @Angarag9z
      @Angarag9z Před rokem +1

      @@nikita-dev thanks

  • @lohithvarma2026
    @lohithvarma2026 Před 5 měsíci

    can we combine the s3 resizing project with this?
    So that when we upload a file it automatically resizes and give the resized image

    • @nikita-dev
      @nikita-dev  Před 5 měsíci

      Yes, but I wouldn't use the signed URL approach (for fetching images)... You should use a cloudfront distribution with an S3 origin, and the lambda would save the resized images to that origin bucket. Then the frontend app will fetch the images through cloudfront

  • @daeun9275
    @daeun9275 Před rokem

    When you show the images using presigned url, when the time expires after some time.. could user still see the picture?

    • @nikita-dev
      @nikita-dev  Před 11 měsíci

      Nope, a new presigned URL needs to be generated once the old one expires

  • @jiwonkim4074
    @jiwonkim4074 Před 10 měsíci

    At 23:01 I get an error of "Error: Region is missing". Both my config and credentials files have region = us-east-1 so I'm not sure why it isn't working

    • @nikita-dev
      @nikita-dev  Před 9 měsíci +1

      do you have your AWS_PROFILE env variable set?

    • @Giiven_Siisanda
      @Giiven_Siisanda Před 3 měsíci

      @@nikita-dev I did set the AWS_Profile but I'm also getting the same error

  • @carlito.pedida-personal
    @carlito.pedida-personal Před 7 měsíci

    Hi, I'm still getting the 404 error even after writing the endpoints in the app.mjs. The console is not logging an error but the page is displaying a 404. Any advice? Thanks!

  • @ashishgarg2471
    @ashishgarg2471 Před rokem

    Hello, I am getting 404 Not Found error till 16:33 time stamp. Any help would be appreciated. Thanks

    • @ashishgarg2471
      @ashishgarg2471 Před rokem

      I have resolved the issue, and working fine. Thanks

    • @carlito.pedida-personal
      @carlito.pedida-personal Před 7 měsíci

      How did you resolve this? I am getting the same error. Thanks in advance!

    • @kaitan4690
      @kaitan4690 Před 6 měsíci

      @@ashishgarg2471 Hi hello! i had the same error, how do you resolve this? many thanks!! =)

  • @vinayakhegde4216
    @vinayakhegde4216 Před rokem

    Will this work if i want to upload videos like we do in youtube ? 🤔🤔

    • @vinayakhegde4216
      @vinayakhegde4216 Před rokem

      My project is OTT platform in mern stack and i want to run shortflims or regional movies (small scale movies) on my site .Is it possible ? with just mern stack and aws s3? I am new to this technology so just want clarify some doubt :)

    • @nikita-dev
      @nikita-dev  Před 11 měsíci +1

      Yes, it is possible. You'll want to set up a CloudFront distribution in front of your S3 bucket to improve performance and reduce costs.

  • @lal9835
    @lal9835 Před rokem

    if toast is not working try adding, {description: "alskjdfklasjdf"}
    property