Next JS Upload File / Images to Local Directory

Ғылым және технология

Pro Next JS: bit.ly/3MXZMGG
In this video we will see how we can upload image files directly inside our local directory inside next js.
We will first create a basic UI to select and upload image file. Then we will write our next js logic so that we can upload file directly inside our public directory.
Source Code: gist.github.com/ndpniraj/2735...
Creating UI: 00:00
File Change Event: 01:40
File Upload Logic: 02:12
Image Upload API: 03:12
Saving Image Inside Local Directory: 06:00
Creating New Folder: 08:18
Testing The App: 09:17
Rendering Local Image Paths: 09:37
Fianl Testing: 11:34
Social Media
/ fsniraj
/ fsniraj

Пікірлер: 87

  • @saybencodes
    @saybencodes Жыл бұрын

    Thank you for this. Great help!

  • @adityapadia7
    @adityapadia711 ай бұрын

    thanks dawg, I didn't get fired because of you. Real G fr

  • @datfeela2578
    @datfeela2578 Жыл бұрын

    thank you, sir, great vid! really helpful and informative!

  • @SheriffKoder9
    @SheriffKoder96 ай бұрын

    Helpful as always !

  • @lucyderojas
    @lucyderojas8 ай бұрын

    works well, thank you Niraj!!!!

  • @abdulsalam-ww8si
    @abdulsalam-ww8si Жыл бұрын

    thanks man you have saved me a lot of trouble ❤❤❤❤

  • @AlpKose-xw6sr
    @AlpKose-xw6sr10 ай бұрын

    You are the best bro. Thanks

  • @26mochammadilhamramadhan85
    @26mochammadilhamramadhan85 Жыл бұрын

    thank you, got new subscriber

  • @wpuncensored
    @wpuncensored8 ай бұрын

    Thank you! I looked of a working way to upload images everywhere...

  • @aminsoraya4517
    @aminsoraya451710 ай бұрын

    you saved my time

  • @nowarm
    @nowarm Жыл бұрын

    thank you very much!

  • @Beast80K
    @Beast80K Жыл бұрын

    I want to send form data containing file, fields to my node js API, from NextJs Api. My react component posts on Nextjs api route, then it forwards data to nodejs api. How can i implement this ??

  • @wassup102
    @wassup102 Жыл бұрын

    nice, thank you sir

  • @reznor_prompt2338
    @reznor_prompt2338 Жыл бұрын

    Thank you!

  • @isme364
    @isme364 Жыл бұрын

    can you please tell me how can i save image data inside my database using prisma orm or just how to get the bytes of the image

  • @jamesrobert5332
    @jamesrobert533210 ай бұрын

    Do you know how to upload Images in Next js 13, would it work the same way with formidable ?

  • @danielbaychev9297
    @danielbaychev9297 Жыл бұрын

    Does anyone know how one would go about uploading different images in different folders? (specific to the user uploading it?) for example /public/images/{user.id}

  • @jagannathrkulakarni
    @jagannathrkulakarni10 ай бұрын

    We can store in different directory right ? By giving absolute path ?

  • @isbelmont
    @isbelmont11 ай бұрын

    In development mode maybe It works but in production I think it doesn't work Read nextjs documentation: Good to know: The directory must be named public. The name cannot be changed and it's the only directory used to serve static assets. Only assets that are in the public directory at build time will be served by Next.js. Files added at runtime won't be available. We recommend using a third-party service like AWS S3 for persistent file storage.

  • @lifeasdev7480

    @lifeasdev7480

    9 ай бұрын

    so it video is useless?

  • @LtTheXamax
    @LtTheXamax Жыл бұрын

    does anyone have a working example for 13.3 nextjs?

  • @paolomaicohome

    @paolomaicohome

    Жыл бұрын

    up

  • @AlirezaMehrabiKali
    @AlirezaMehrabiKali9 ай бұрын

    i got an issue here, after deploy website on server, public directory not recognize, all images goes to .next/static/media. for having those picture you should run command npm run build every time you upload new image. is there any way to solve this problem?

  • @jatinduggal1975

    @jatinduggal1975

    3 ай бұрын

    i am facing same problem, did you find the solution ???

  • @thuglifeinventor
    @thuglifeinventor10 ай бұрын

    thanks so much I just copied your code and it works

  • @llibanogs
    @llibanogsАй бұрын

    thx buddy

  • @oliviaarche1992
    @oliviaarche1992 Жыл бұрын

    Please share the repository link for the tutorial. Thanks

  • @user-rf7ye1ne9l
    @user-rf7ye1ne9l28 күн бұрын

    dose it work after build

  • @yasharodiya2085
    @yasharodiya2085 Жыл бұрын

    what all things we need to run to get all the files that you have in the beginning? I'm new to Next JS.

  • @fsniraj

    @fsniraj

    Жыл бұрын

    nextjs.org/docs/getting-started

  • @RameshPyakurel1
    @RameshPyakurel1 Жыл бұрын

    This is great. Thanks. Can you also tell me how can I send the same image to API Endpoint (External) where I'd like to edit the image for example and get the response from that server?

  • @fsniraj

    @fsniraj

    Жыл бұрын

    Thats a little extra work but here I did a video about all those things you can check this out kzread.info/dash/bejne/n2upsZpuoJDJYLQ.html this is the part where we are uploading image to the cloudinary using node js. You can do this same inside your next js api

  • @RameshPyakurel1

    @RameshPyakurel1

    Жыл бұрын

    @@fsniraj Thank you for your suggestion. I watched the video but I cound't make the code to work. If you could show how to write the code in next js api that would be great. If not, could you please direct me to some post or thread which could help me solve this issue. Anyways thanks for your awesome videos.

  • @nolep5555
    @nolep5555 Жыл бұрын

    which better or common to upload image in next js, to cloud or local directory?

  • @fsniraj

    @fsniraj

    Жыл бұрын

    Cloud is best in my thinking.

  • @isbelmont

    @isbelmont

    11 ай бұрын

    If you have your own server then local, You did comment 7 months ago, I'd like to know what you choosed

  • @nolep5555

    @nolep5555

    11 ай бұрын

    @@isbelmont sure, I will chose cloud

  • @user-wr7ou8ih5s
    @user-wr7ou8ih5s2 ай бұрын

    is this recommended ? and is it deployment ready or just for knowledge ?

  • @fsniraj

    @fsniraj

    Ай бұрын

    Not recommended for production

  • @Ayushshah
    @Ayushshah3 ай бұрын

    Bro this is not working in NextJs 13+

  • @bacharelkarni1996
    @bacharelkarni1996 Жыл бұрын

    guys, i'm having a bad time with a project that has a close deadline, and i need to upload the files into the public folder but i can't understand a single thing about typescript. Can you suggest something(a video, a blog ...) that shows how to do the same thing with next and javascript instead of ts. thank you so much

  • @reznor_prompt2338

    @reznor_prompt2338

    Жыл бұрын

    just dont declare the types

  • @fsniraj

    @fsniraj

    Жыл бұрын

    Yes you can simply remove the **:type** or **as type** and that will be javascript.

  • @bacharelkarni1996

    @bacharelkarni1996

    Жыл бұрын

    @@reznor_prompt2338 thank you

  • @bacharelkarni1996

    @bacharelkarni1996

    Жыл бұрын

    @@fsniraj Thank you man

  • @tofiknuryanto
    @tofiknuryanto Жыл бұрын

    but the images cannot accessed on production mode

  • @bacharelkarni1996

    @bacharelkarni1996

    Жыл бұрын

    Is there an alternative to this cuz i'm facing this exact prob

  • @tofiknuryanto

    @tofiknuryanto

    Жыл бұрын

    Absolutely you need 1 step to access your image after image uploaded. 1. Re build your app, so image will detected 😁 or ... 2. Create an API to serve your image. Example: Create api file usual /pages/api/images/[filename].jsx import fs read data file using query filename Send the image to client 😁

  • @bacharelkarni1996

    @bacharelkarni1996

    Жыл бұрын

    @@tofiknuryanto thanks

  • @sodiqayilara1519

    @sodiqayilara1519

    Жыл бұрын

    @@tofiknuryanto This doesn't work at scale, you are saving files in-memory. You need to send your file to database.

  • @tofiknuryanto

    @tofiknuryanto

    Жыл бұрын

    @@sodiqayilara1519 still work for me.

  • @user-nm8un9fl7x
    @user-nm8un9fl7x9 ай бұрын

    te amo

  • @mohammedarshad8531
    @mohammedarshad8531 Жыл бұрын

    How can we save file to mongoDb database?

  • @fsniraj

    @fsniraj

    Жыл бұрын

    Short answer, mongodb is not ment to save files.

  • @vernevens1598
    @vernevens15987 күн бұрын

    How many users are going to want to upload from their computer to a folder that they shouldn't be able to access?

  • @chanra4948
    @chanra4948 Жыл бұрын

    import fs from "fs/promises"; doesn't work on client side | Don't waste your time here if you see that

  • @malikbhai2285
    @malikbhai228511 ай бұрын

    Dear sir , I m from Pakistan... Please make a video with next. Js Full stack Mongodb Add title, Description, category with Image With Same work PDF file upload and Videos Add from front end and back End Then Image Display, PDF file download and Videos play work

  • @RaviGupta-rn8rr
    @RaviGupta-rn8rr29 күн бұрын

    Image is uploaded but after building the next js application it's giving me 404

  • @fsniraj

    @fsniraj

    28 күн бұрын

    here is the new way kzread.info/dash/bejne/qqeivKatgranico.html

  • @rabiulhasannayan8220
    @rabiulhasannayan8220 Жыл бұрын

    is there any github link ?

  • @fsniraj

    @fsniraj

    Жыл бұрын

    Just added in the description

  • @itsabun
    @itsabun Жыл бұрын

    Sorry but, can you make this videos again, but with new setup of Next JS 13?

  • @fsniraj

    @fsniraj

    Жыл бұрын

    I am working on it, the next video will be the same as you want.

  • @itsabun

    @itsabun

    Жыл бұрын

    @@fsniraj Wow It's Great.! 🤩. I can't wait for it

  • @elementalhero9939
    @elementalhero9939 Жыл бұрын

    Doesn't work in production :(

  • @fsniraj

    @fsniraj

    Жыл бұрын

    Yes the vercel doesn't allow you to upload large files

  • @abdulkaharNayeem

    @abdulkaharNayeem

    Жыл бұрын

    @@fsniraj no i am trying with cpanel and digital ocean also both not showing the images. its uploaded but not showing

  • @InspirasiMedia
    @InspirasiMedia10 ай бұрын

    Great tutorial sir, but why this method doesn't work in production?

  • @MauFranchini

    @MauFranchini

    10 ай бұрын

    As @isbelmont mentioned: Read nextjs documentation: Good to know: The directory must be named public. The name cannot be changed and it's the only directory used to serve static assets. Only assets that are in the public directory at build time will be served by Next.js. Files added at runtime won't be available. We recommend using a third-party service like AWS S3 for persistent file storage. So that's a hard constraint

  • @afuhchristianforkoum7229
    @afuhchristianforkoum7229 Жыл бұрын

    Doesn't work on production

  • @abdulkaharNayeem

    @abdulkaharNayeem

    Жыл бұрын

    same problem.. image not showing on production

  • @abdulkaharNayeem

    @abdulkaharNayeem

    Жыл бұрын

    did you find the solution?? if anyone get solution’s let me know please

  • @tonhom260

    @tonhom260

    Жыл бұрын

    @@abdulkaharNayeem create own server using express js

  • @abdulkaharNayeem

    @abdulkaharNayeem

    Жыл бұрын

    @@tonhom260 can you show me the code how can i do that..sorry for asking.but its need for me

  • @anujbhati8994
    @anujbhati89944 ай бұрын

    Guys this will not going to work on production so don't waste your time here, Use a third party service like cloudinary or you can use an express server for storing static data in local directory.

  • @macmototv8534
    @macmototv85349 ай бұрын

    This tutorial is useless, it will not work in production

  • @jeanie9995
    @jeanie99956 ай бұрын

    test

  • @Hypergraph
    @Hypergraph Жыл бұрын

    Don't try this in production. It doesn't work.

  • @abubalo

    @abubalo

    Жыл бұрын

    Yep. Better to use Cloudinary, S3 bucket or equivalent.

  • @AjayShakya-jq4wb
    @AjayShakya-jq4wb19 күн бұрын

    Useless

  • @garbjorn1757
    @garbjorn1757 Жыл бұрын

    To get just the file extension just make it return Date.now().toString() + "." + path.originalFilename.split(".").pop()

  • @frontendzonedotcom
    @frontendzonedotcom11 ай бұрын

    why formidable is needed here? is can't be done without it

Келесі