Cloudinary Image Upload - the easiest way - mern stack

Поделиться
HTML-код
  • Опубликовано: 25 май 2022
  • We are going to teach you how to upload image in cloudinary in base 64, without any extra steps, or over complicated code, it will be very easy to follow.
    👉 - Delete easily image in cloudinary: • Cloudinary delete imag...
    👉 - Cloudinary upload multiple images - MDB Carousel example - MERN Stack: • Cloudinary upload mult...
    👉 Cloudinary update image in backend - mern stack: • Cloudinary update imag...
    👉 Github link: github.com/emmannweb/mernstac...
    👉 Membership: / @emmannweb
    ☕ Buy me a coffee: www.buymeacoffee.com/codingac...
    RUclips TUTORIALS
    - Worpdress Tutorial: • Wordpress tutorial - h...
    - Custom post type and taxonomy filter: • Custom post type with ...
    - Cloudinary CRUD operation: • Cloudinary update imag...
    - HTML and CSS Website design tutorial from scratch: • html and css website d...
    - MERN Stack from scratch: • mongodb express react ...
    - MERN Stack with Redux Toolkit: • Redux Tutorial / Redux...
    Cloudinary Image Upload - the easiest way - mern stack
    CODING ACADEMY is a programming channel that aim to teach programming stuff in a simple way.
    If you are looking for Wordpress tutorial, React, MongoDB, ect this is the right channel for you.
    Don´t forget To Subscribe and Share with other Friends
    Subscribe To Coding academy : / @emmannweb
    You Can Follow on Facebook :
    CODING ACADEMY is an online media that was created to teach programming to any person around the world who feel the need to learn programming. We teach in a simple way and make it easy to understand.
    Our community ( CODING ACADEMY) fans greatly appreciate this initiative,
    #coding academy #Wordpress #coding

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

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

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

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

      Thank you. Glad to hear it!

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

    Very nice and easy to know, thanks so much 😊

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

    Thanks, Brother. Much appreciation for you.

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

      Thank you so much! You're welcome.

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

    thank you for this tutorial!

  • @node991
    @node991 2 месяца назад +1

    supportive video & easy to know! Thanks brother

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

      Glad you liked it!

  • @lokeshchauhan6253
    @lokeshchauhan6253 Месяц назад +1

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

  • @devmentor2022
    @devmentor2022 Год назад +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  Год назад +1

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

    • @devmentor2022
      @devmentor2022 Год назад +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  Год назад +1

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

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

    nice video thank you It worked

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

    Thanks making devs life easy ❤❤

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

      My pleasure 😊

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

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

    • @emmannweb
      @emmannweb  Год назад +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  Год назад +1

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

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

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

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

      github.com/emmannweb/mernstackproject

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

    Very cool!
    One more subscribed.

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

      Awesome! Thank you.

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

    Thankyou sir, your code is helped me

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

    This is amazing

  • @alihourag
    @alihourag 10 месяцев назад +1

    My G, God bless you

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

      Thank you so much bro!

  • @ernzotech
    @ernzotech 12 дней назад

    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"

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

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

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

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

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

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

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

      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 3 месяца назад +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 3 месяца назад

      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  3 месяца назад +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 3 месяца назад

      @@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

  • @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.

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

    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  5 месяцев назад

      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.

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

    i love you bro!

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

      thank you, love you too bro

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

    Gracias!

  • @user-dj8hh7ys2f
    @user-dj8hh7ys2f 2 месяца назад +1

    Life Saver Dude

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

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

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

      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.

  • @manukrishnan4318
    @manukrishnan4318 8 месяцев назад +1

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

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

      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.

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

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

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

      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.

  • @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
      }));

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

    How can I display images from a specific folder in cloudinary

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

      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.

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

    Thnks Eng

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

      you're welcome!

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

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

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

      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.

  • @theycallmejatin
    @theycallmejatin 11 месяцев назад

    How many years have you been learning to code ?

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

      About 7 years.

    • @theycallmejatin
      @theycallmejatin 11 месяцев назад

      @@emmannweb damn what's your age now

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

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

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

      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 10 месяцев назад

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

    • @emmannweb
      @emmannweb  10 месяцев назад +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.

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

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

    • @emmannweb
      @emmannweb  Год назад +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 Год назад

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

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

      @@abhishaianandaraj.j6045 show your code

    • @abhishaianandaraj.j6045
      @abhishaianandaraj.j6045 Год назад

      @@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 Год назад

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

  • @user-ow7db4fe4q
    @user-ow7db4fe4q Год назад +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.

    • @user-ow7db4fe4q
      @user-ow7db4fe4q Год назад +1

      @@emmannweb Ok.

  • @johnraphael7700
    @johnraphael7700 Год назад +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 Год назад

    Screen is not clearly visible

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

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

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

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

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

      can you be more specific?

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

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

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

      ​ @Shura Stun get it thank you.

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

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

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

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

  • @ernzotech
    @ernzotech 12 дней назад

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

    • @emmannweb
      @emmannweb  12 дней назад

      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 12 дней назад

      I have done that correctly @@emmannweb