Cloudinary Image Upload - the easiest way - mern stack

Поделиться
HTML-код
  • Опубликовано: 12 ноя 2024

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

  • @lokeshchauhan6253
    @lokeshchauhan6253 7 месяцев назад +2

    Thanks bro i was struggling to upload for over 8 hrs thank you very much

    • @emmannweb
      @emmannweb  7 месяцев назад

      You're welcome!

  • @code991code
    @code991code 7 месяцев назад +1

    supportive video & easy to know! Thanks brother

    • @emmannweb
      @emmannweb  7 месяцев назад

      Glad you liked it!

  • @TomatoCultivator219
    @TomatoCultivator219 2 года назад +1

    Amazing video! I was stuck for a long time before watching this

    • @emmannweb
      @emmannweb  2 года назад +1

      Thank you. Glad to hear it!

  • @trungkienofficial8085
    @trungkienofficial8085 Год назад +3

    Very nice and easy to know, thanks so much 😊

  • @sdsumonto2350
    @sdsumonto2350 Год назад +1

    Thanks making devs life easy ❤❤

  • @azimuddinahamed
    @azimuddinahamed 2 года назад +1

    Thanks, Brother. Much appreciation for you.

    • @emmannweb
      @emmannweb  2 года назад

      Thank you so much! You're welcome.

  • @TamilMani-t4l
    @TamilMani-t4l 8 месяцев назад +1

    Life Saver Dude

    • @emmannweb
      @emmannweb  8 месяцев назад

      You're welcome!

  • @sugoonese4024
    @sugoonese4024 4 месяца назад +1

    Lovely video! Simple and easy. May I ask the purpose for storing a public_id in the image? is the URL not enough for displaying the image on the frontend? Thanks!

    • @emmannweb
      @emmannweb  4 месяца назад

      Thank you so much! Well, the "public_id", you would use it, for instance, if you want to delete an image. Application example: github.com/emmannweb/blog-mern-app/tree/main
      check this project (front an back)

  • @toyinatofarati5512
    @toyinatofarati5512 9 месяцев назад +1

    Great! did you experience and CORS error when you deployed this project?

    • @emmannweb
      @emmannweb  9 месяцев назад

      Not at all. Because i have added this line in package.json in frontend folder : "proxy":"host: YOUR_BACKEND_PORT". in localhost: "proxy": "localhost:8000" for ex. If 8000 is your backend port.

    • @toyinatofarati5512
      @toyinatofarati5512 9 месяцев назад +1

      @@emmannweb ok, I will do just that. I hope it will resolve the cors error I am getting from cloudinary. Thank you

    • @toyinatofarati5512
      @toyinatofarati5512 9 месяцев назад

      still experiencing the CORS error, although i am going through a different approach in uploading the files but it works on my local machine

    • @emmannweb
      @emmannweb  9 месяцев назад +1

      @@toyinatofarati5512 do you have cors package installed in backend and helmet?
      if so, in your backend server file, add: app.use(
      helmet.contentSecurityPolicy({
      useDefaults: true,
      directives: {
      "img-src": ["'self'", "https: data:"]
      }
      })
      )
      for CORS: app.use(cors());
      it should work, unless you missed something.
      Other consideration, if it works on localhost, you're almost there, in your package.json, "proxy": "localhost:BK_PORT", replace localhost by your server IP. and restart it again.

    • @toyinatofarati5512
      @toyinatofarati5512 9 месяцев назад

      @@emmannweb thank you for your time I will do as you have said, if it doesn't work out I might share my GitHub link

  • @monj3876
    @monj3876 2 года назад +1

    thank you for this tutorial!

  • @MatheusSilva-qm3ph
    @MatheusSilva-qm3ph 10 месяцев назад +1

    Very cool!
    One more subscribed.

    • @emmannweb
      @emmannweb  10 месяцев назад

      Awesome! Thank you.

  • @stickshift583
    @stickshift583 Год назад +1

    nice video thank you It worked

  • @nikkv9
    @nikkv9 Год назад

    Thankyou sir, your code is helped me

  • @devmentor2022
    @devmentor2022 2 года назад +1

    nice video thank you. I think you should describe more about the last user interface but totally I got the idea and worked with me

    • @emmannweb
      @emmannweb  2 года назад +1

      Thanks for the idea! But could elaborate better? did you suggest that i give a better look on the user interface?

    • @devmentor2022
      @devmentor2022 2 года назад +1

      @@emmannweb yes it wasn't clear how you make the requests to your backend from client side .. so it was clear for when you were working on vscode .. but when you used the user browser I couldn't get it. But anyway it solved my problem .. 🥰🥰🥰🥰

    • @emmannweb
      @emmannweb  2 года назад +1

      ​ @Dev mentor okay... Happy to hear that!

  • @ernzotech
    @ernzotech 5 месяцев назад

    I am having this error "Missing required parameter - file"while trying to add a photo to cloudinary from Postman while testing it "Missing required parameter - file"

  • @gregfredder8645
    @gregfredder8645 2 года назад +1

    Thank you for this video can you provide the link for the react form project?

    • @emmannweb
      @emmannweb  2 года назад

      github.com/emmannweb/mernstackproject

  • @techexplained-254
    @techexplained-254 Год назад +1

    This is amazing

  • @malekguedda235
    @malekguedda235 Год назад +1

    so we don't need to use multer at all here ?

    • @emmannweb
      @emmannweb  Год назад +1

      Exactly, we don't need to use multer in this case. If I would use multer, i won't use cloudinary vice-verca. Multer is very popular and it's known to save images locally. As i like more flexibility and portability, I opt for cloudinary.

  • @Manu_krishnan
    @Manu_krishnan Год назад +1

    if i add more tan 100 pictures then it become slow ??? when storing imges in mongodb then it become very slow

    • @emmannweb
      @emmannweb  Год назад

      Well good question, i always advice that as developer we need to know all possibilities to upload images but also be able to make good choice is one of our job as developer. Sure, you would have a higher payload from the json reponse that could lead to a bad experience of the user.

  • @MrPindro
    @MrPindro Год назад +1

    Well done chap, any chance of knowing how to upload an array of images into cloudinary and mongodb instead?

    • @emmannweb
      @emmannweb  Год назад +1

      Well, we already did a video about that: ruclips.net/video/GEE0jNxC8Gw/видео.html

  • @luchoherrera8536
    @luchoherrera8536 2 года назад +1

    i love you bro!

    • @emmannweb
      @emmannweb  2 года назад

      thank you, love you too bro

  • @codingmadeeasy3913
    @codingmadeeasy3913 2 года назад +1

    How can I display images from a specific folder in cloudinary

    • @emmannweb
      @emmannweb  2 года назад

      To display images from a specific folder, as i understand your question, you should create your specific folder before, as i showed you in the video. Since you have pre-configured your specific folder in the backend API, you don't need to worry about them. It will display automacally, from that particular folder, once you make the API call.

  • @frandepaulo
    @frandepaulo 2 года назад +1

    Gracias!

  • @stuartYoung559
    @stuartYoung559 10 месяцев назад

    HEY ! im uploading the image from my local files , and posting it using axios to cloudinary
    but im getting error like this:
    TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string.
    im worried that Cloudinary accept url of image , but when i console logged on image i got an alien huge massive data of leters. those are no way url to image

    • @emmannweb
      @emmannweb  10 месяцев назад

      Hi, In this tuto, the image is converted to Base64, cause Cloudinary support that format, maybe you missed something, the code is still working. I would suggest you to console.log what you'll send to backend and also console.log in backend what you received from frontend, so that you know exactly what's going on.

  • @BGMLismylife
    @BGMLismylife Год назад

    How many years have you been learning to code ?

  • @ernestisibor-s6z
    @ernestisibor-s6z Год назад +1

    You did not use multer?

    • @emmannweb
      @emmannweb  Год назад

      No, i'm not. It's not mandatory. But If you want to save your images in your project folder you could do so.

    • @ernestisibor-s6z
      @ernestisibor-s6z Год назад +1

      @@emmannweb Ok.

  • @hassanomar4950
    @hassanomar4950 Год назад +1

    Thnks Eng

  • @abhishaianandaraj.j6045
    @abhishaianandaraj.j6045 2 года назад +1

    What do I do if I have a payload too large error?

    • @emmannweb
      @emmannweb  2 года назад +1

      good question. try to this snippet in your backend server API:app.use(bodyParser.json({limit: '100mb'}));
      app.use(bodyParser.urlencoded({ // to support URL-encoded bodies
      limit: '100mb',
      extended: true
      }));

    • @abhishaianandaraj.j6045
      @abhishaianandaraj.j6045 2 года назад

      @@emmannweb I did that but still it's showing the same error

    • @emmannweb
      @emmannweb  2 года назад

      @@abhishaianandaraj.j6045 show your code

    • @abhishaianandaraj.j6045
      @abhishaianandaraj.j6045 2 года назад

      @@emmannweb const app = express();
      app.use(express.json());
      app.use(bodyParser.json({limit:'100mb'}));
      app.use(bodyParser.urlencoded({extended:true,limit:'100mb'}));
      app.use(cors({
      origin:"*",
      methods:["GET","POST","PUT"],
      "Content-Type":"application/json",
      }));

    • @abhishaianandaraj.j6045
      @abhishaianandaraj.j6045 2 года назад

      if i post a large file(an image)it shows a cors error also. but for small files, it works normally

  • @qamarzaman-qz
    @qamarzaman-qz Год назад +1

    Can I do this in wordpress, is it possible if any one know themn please reply

    • @emmannweb
      @emmannweb  Год назад

      This implementation is for Nodejs App, but Cloudinary support many programming languages, check their documention. With Wordpress you can do it via plugin or custom code following their documention on that matter.

    • @qamarzaman-qz
      @qamarzaman-qz Год назад

      @@emmannweb brother can you tell me?, which process is this called of upload my wordpress images to cloudinary
      Even from the frontend

    • @emmannweb
      @emmannweb  Год назад +1

      @@qamarzaman-qz cloudinary.com/documentation/wordpress_integration
      wordpress.org/plugins/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/
      I never used them but this should give you a starting point.

  • @bitcoinizados4541
    @bitcoinizados4541 2 года назад +1

    Hello, Very cool, what change would I have to make to upload multiple images?. Nice tutorial, thanks.

    • @emmannweb
      @emmannweb  2 года назад +4

      Your backend api that has the image field, you'll set it as array of ojects: [{}]; in your input file you'll add "multiple" as attribute. Your image state will be also array: const [images, setImages] = useState([]);
      const onChange = e => {
      const files = Array.from(e.target.files)
      files.forEach(file => {
      const reader = new FileReader();
      reader.onloadend = () => {
      setImages(oldArray => [...oldArray, reader.result])
      }
      reader.readAsDataURL(file)
      })
      }

    • @emmannweb
      @emmannweb  2 года назад +1

      This video is the answer to your question: ruclips.net/video/GEE0jNxC8Gw/видео.html

  • @dannelmulja8958
    @dannelmulja8958 Год назад +1

    Hello sir, thank you for uploading this video,, it is very useful
    Although I encountered a problem
    In my post method, I used the same way as you did where I make a const result = await cloudinary.uploader.upload
    but it seems to not be working, because when I check my console it kept throwing to my catch error. I dont know why because I tried a lot of solutions but still it doesnt work
    Now my image base64 string does not include the data:image/jpeg;base64 but I tried adding them to my image string but it still does not work.
    Perhaps is there something wrong with my configuration or anything? Should the CLOUD_KEY and the other config variables have the " " as how we copied from the cloudinary?
    I really don't understand why my const result = await cloudinary.uploader.upload does not work, I tried to console.log under this function to check if it works but it does not output my log so I'm certain the problem is from that function
    please help thank you :)

    • @emmannweb
      @emmannweb  Год назад

      Sorry for delay, you have few things to consider, when you're dealing with trouble first of all, is to download the code base to compare your code with,. Secondly it could be your configuration file with the values that come from .env file, recently i'm using the same code
      in this video lesson: ruclips.net/video/_FJMRSlHh8k/видео.html it works really well. Other factor, in your package.json in frontend folder, you should add a "proxy": "localhost:8000", 8000 will represent your choosing backend port, if yours is 9000 you put it. Verify it in my cod base. There is no secret,i think you can do it.

  • @bappirahman3294
    @bappirahman3294 Год назад

    How to change temp files location? I'm using a serverless read-only server which allow write only one location. How can I set cloudinary to store on that location ? The default location isn't working

    • @emmannweb
      @emmannweb  Год назад

      Could you be more specific, i mean with more details on the stacks you're using. However to find your implementation type and the way you should do it check this link: cloudinary.com/documentation/image_upload_api_reference#explicit, in that Doc you'll find implemenation for PHP, Ruby, Java etc.

    • @bappirahman3294
      @bappirahman3294 Год назад

      @@emmannweb I'm using node and cyclic.sh server when I get the image from frontend cloudinary create temp file in local environment before uploading to cloudinary storage. I want to change the location of that temp files

    • @emmannweb
      @emmannweb  Год назад

      @@bappirahman3294 ok i get it, did you use other dependency like multer ? etc., in my opinion after the configuration of Cloudinary in the backend, it doesn't require a temp file (i think it's optional). The file name coming from the frontend to backend should exist exactly the same. Other consideration, before sending the image file with convert it to a string in base64, i-e if you can send your text fields in the backend from the frontend(you don't need extra configuration), it supposed to work, i think. All the data like text and image are sent to backend like string. I hope you get it!

    • @bappirahman3294
      @bappirahman3294 Год назад

      @@emmannweb I used multer but I removed it as a dependency and uninstalled it but still I'm getting write error

    • @emmannweb
      @emmannweb  Год назад

      @@bappirahman3294 if your configuration is correct according to what we've showed in this video it should work. However, in your form before sending the data to the backend console.log them to check if all fields have a value same thing with the image field and verify its name front and back. 2) Probably if you're using Morgan package as middleware, check if your endpoint is reached 3) To enable image of a certain size to be uploaded, use this example : app.use(bodyParser.json({limit: '100mb'}));
      app.use(bodyParser.urlencoded({ // to support URL-encoded bodies
      limit: '100mb',
      extended: true
      }));

  • @sutoraika6976
    @sutoraika6976 2 года назад

    do you know how to automatically rename the file before upload? just asking.

    • @emmannweb
      @emmannweb  2 года назад

      I think it's possible but i didn't implement it yet. You'll need extra logic to name it randomly or with unique name and increment the value.

  • @jatinsaini2794
    @jatinsaini2794 2 года назад +1

    I got an error
    Which says: MISSING REQUIRED PARAMETER - FILE
    PLEASE HELP ME❤️❤️

    • @emmannweb
      @emmannweb  2 года назад

      1) Seems like the image was not uploaded, check the image field name (front and back),
      2) before sending the request, use console.log to check if you have all the fields value.
      3) Compare the github project files, to verify what you miss.

  • @raphael_john_ng
    @raphael_john_ng Год назад +1

    Please can I get the source code?

    • @emmannweb
      @emmannweb  Год назад

      Github link: github.com/emmannweb/mernstackproject

  • @MoMoMOMO-pl9fj
    @MoMoMOMO-pl9fj Год назад

    where is the complet proj

    • @emmannweb
      @emmannweb  Год назад

      This tuto was to show how to deal with images.

  • @suhailbhat9866
    @suhailbhat9866 2 года назад

    Screen is not clearly visible

    • @emmannweb
      @emmannweb  2 года назад

      you could check you internet connection. i double check on my side, i saw it's fine.

  • @shurastun5530
    @shurastun5530 2 года назад +1

    I found "OK" very irritating. Sorry. Like it was repeated for million times.

    • @emmannweb
      @emmannweb  2 года назад

      can you be more specific?

    • @shurastun5530
      @shurastun5530 2 года назад +2

      @@emmannweb try to reduce your expression "OK" when talking.

    • @emmannweb
      @emmannweb  2 года назад

      ​ @Shura Stun get it thank you.

    • @alexvolkov529
      @alexvolkov529 Год назад +1

      @@emmannweb and 'I mean' as well...

    • @emmannweb
      @emmannweb  Год назад

      @@alexvolkov529 sorry guys, i'll try my best

  • @ernzotech
    @ernzotech 5 месяцев назад

    I am getting this error on POSTMAN "Unknown API key '777252576991944'," while trying to upload photo

    • @emmannweb
      @emmannweb  5 месяцев назад

      According to you error, seems like you have a problem with your Cloudinary credentails. Double check them. Don`t forget to put them with their correct name in .env file.

    • @ernzotech
      @ernzotech 5 месяцев назад

      I have done that correctly @@emmannweb