How to upload images to CloudFlare R2 in Next.js

Поделиться
HTML-код
  • Опубликовано: 17 май 2024
  • My Products
    🏗️ WDC StarterKit: wdcstarterkit.com
    📖 ProjectPlannerAI: projectplannerai.com
    🤖 IconGeneratorAI: icongeneratorai.com
    📝 ThumbnailCritique: thumbnailcritique.com
    Useful Links
    💬 Discord: / discord
    🔔 Newsletter: newsletter.webdevcody.com/
    📁 GitHub: github.com/webdevcody
    📺 Twitch: / webdevcody
    🤖 Website: webdevcody.com
    🐦 Twitter: / webdevcody

Комментарии • 34

  • @SeibertSwirl
    @SeibertSwirl 15 дней назад +11

    Good job babe! Love ya!

    • @MohamedElguarir
      @MohamedElguarir 15 дней назад +1

      WTF

    • @SeibertSwirl
      @SeibertSwirl 15 дней назад +3

      @@MohamedElguarir it’s ok. I can say that to him, I’m his parole officer.

    • @WebDevCody
      @WebDevCody  15 дней назад +3

      Thanks babe love you!

  • @ianfrye8988
    @ianfrye8988 15 дней назад

    Ayeeee you got it figured out. Great video my friend

  • @sameerahmedk
    @sameerahmedk 14 дней назад

    Have you considered react form libraries?
    Because I recall reading the docs and they mentioned that custom forms cause unnecessary rerenders so better to use a library that tackles that. Would love to hear your thoughts if you've looked into it and still chose this approach

  • @MohamedElguarir
    @MohamedElguarir 15 дней назад +4

    what about timeouts, bigger files ?
    I think using presigned uploads are much better + you'll save bandwidth ==> saving you $$

    • @WebDevCody
      @WebDevCody  15 дней назад +1

      Yes, on larger files you’d want a presigned url. The issue I have with presigned urls is that it exposes your bucket name and anyone can ddos your bucket and run up a large bill. Also with R2 there isn’t a way to limit file size, so technically someone could just keep uploading huge files to your bucket.

  • @rafamuttoni
    @rafamuttoni 14 дней назад

    interesting how you organize some parts of the application logic in this "use-cases" folder, have you talked about that in any recent video?

    • @WebDevCody
      @WebDevCody  14 дней назад

      It’s related to clean architecture or layered architecture. I think I have a few videos about it.

  • @essaadi_elmehdi6784
    @essaadi_elmehdi6784 15 дней назад

    Great video, thank you for sharing
    You did the ref stuffs to reset the file input after a successful upload, because there is no way to reset it than making it's equal undefined using the ref

    • @WebDevCody
      @WebDevCody  15 дней назад +1

      I can’t figure out a way to reset the file input without a ref 🤷‍♂️

  • @joshuaroland9876
    @joshuaroland9876 15 дней назад

    Thank you so much for this video. I tried to do this by uploading multiple images and videos but somehow I can’t do that when I deploy to production because of vercel’s body limit size. Even after trying presignedURLs, I still get the same error. From your experience, do you think creating an external nodejs server for this would solve the issue?

    • @WebDevCody
      @WebDevCody  15 дней назад +1

      A presigned url shouldn’t have an upload limit, or if it does it’s a few GB. I’d try that again.

    • @joshuaroland9876
      @joshuaroland9876 15 дней назад

      @@WebDevCody thank you so much for the reply. I’ll implement this night again. Maybe I was doing it wrong before. Had to follow your image gallery video with next-cloudinary as an alternative. Your videos really help me 🤩🤩

    • @pawixu
      @pawixu 15 дней назад +1

      @@joshuaroland9876 just make sure that you upload files to presigned url using client. You can do it 🤛.

    • @joshuaroland9876
      @joshuaroland9876 15 дней назад +1

      @@pawixu thank you. I’ll return here once I get it sorted🦾

  • @WebDevCodeCrush
    @WebDevCodeCrush 15 дней назад

    I am curious why you opted for this storage service. As a starter kit might it be a more simple and upload efficient option to use something like UploadThing? The only options I’m familiar with are Upload Thing, Cloudinary, and the Convex storage so I’m truly interested in your reasoning and thought process.

    • @WebDevCody
      @WebDevCody  15 дней назад +1

      For storage, you won’t get as close to “free” than with S3 or R2. Almost any production application I know uses S3 for storing files. Convex even uses s3 behind the scenes, they just abstract it away. I’m pretty sure upload thing also uses s3.

    • @WebDevCodeCrush
      @WebDevCodeCrush 14 дней назад

      @@WebDevCody Yes, I figured S3 was the case. Most of my projects are very small, either test cases or hobby projects so the simplicity of upload thing or convex is easy, but at large scale would probably go directly to S3 once I was comfortable with it.

  • @JediMediator
    @JediMediator 15 дней назад

    I come from express and got used to needing multer for any upload needs. Why don't you need it here?

  • @yunyang6267
    @yunyang6267 15 дней назад

    It would be nice to add a functionality to crop the image to a certain size

  • @griffadev
    @griffadev 15 дней назад

    Meme type 😂 love it

  • @Tenseic
    @Tenseic 15 дней назад +1

    Wouldn’t it be better to create presigned urls and let the user directly upload to the bucket?

    • @WebDevCody
      @WebDevCody  15 дней назад

      Yes, I thought that as well until I learned anyone can ddos your private bucket and you’ll be charged a lot of money. This gives you more control over abstraction away the bucket and also prevents the scenario where someone uploads files but the second part of the request never goes through causing orphaned files

  • @sumitpurohit8849
    @sumitpurohit8849 15 дней назад +1

    I wonder if this can affect the vercel's bill by sending the entire file to api route. Instead can we just generate the presigned url and send it to client and upload the file from there.

    • @joshuaroland9876
      @joshuaroland9876 15 дней назад

      I have tried doing this and still vercel doesn’t let me upload larger files. I’ve been thinking of creating my own node server instead

    • @Yusuf-ok5rk
      @Yusuf-ok5rk 15 дней назад

      @@joshuaroland9876 you will be serverless and you will be happy

    • @hashgraph1832
      @hashgraph1832 15 дней назад

      ​@@joshuaroland9876you can upload large file, using presigned url

    • @pawixu
      @pawixu 15 дней назад +1

      Yes, it affects the bill. There's a better way, most data storages allows to create signed/presigned upload url, which you generate on your server, then send it back to client and then client uploads the file to bucker/r2.

    • @WebDevCody
      @WebDevCody  15 дней назад +1

      I’m not deploying to vercel, but yes you’d probably most definitely want a presigned post to your bucket directly to save on bandwidth

  • @vickoalan
    @vickoalan 15 дней назад

    sorry, but I think this is not a good way,
    using resigned URLs is the best way,
    What if the size of the image is too big ?