How to upload image on cloudinary in ASP.NET MVC?


I have just started using Cloudinary to upload images for my client's project there & I was trying to upload an image using explanation provided here https://cloudinary.com/documentation/dotnet_image_upload but it's not working for me, can you explain a complete example of this? Or any link of tutorial will also help, thanks.


Asked by:- jon
0
: 8152 At:- 5/21/2018 6:02:30 PM
C# Cloudinary Image upload ASP.NET MVC







1 Answers
profileImage Answered by:- Vinnu

You can upload images on cloudinary following these steps for C# .NET

  1. Install Cloudinary using Nuget package manager console.
    Install-Package CloudinaryDotNet?
  2. Now you need to use the following namespaces in your C# code
     using System.Collections.Generic;
    using System.Web;
    using CloudinaryDotNet;
    using CloudinaryDotNet.Actions;?
  3. Create  Cloudinary Object using API key and password provided to you after sign up, pass the image file to ImageUploadParams() function and call cloudinary's Upload function
    var myAccount = new Account { ApiKey = apiKey, ApiSecret = apiSecret, Cloud =  cloudName }; 
    Cloudinary _cloudinary = new Cloudinary(myAccount);
    
    var uploadParams = new ImageUploadParams()
    {
      File = new FileDescription(@"c:\my_image.jpg");
    };
    var uploadResult = _cloudinary .Upload(uploadParams);??
  4. get Uploaded file url using uploadResult.SecureUri.AbsoluteUri;
  5. That's it you are done, If you want to pass additional details like Image Width, height, you can use the C# code like below
     var uploadParams = new ImageUploadParams {
     File = new  FileDescription(file.FileName,file.InputStream), 
    //transformation code here
    Transformation = new  Transformation().Width(200).Height(200).Crop("thumb").Gravity("face") 
      };
     
    var uploadResult = _cloudinary.Upload(uploadParams);?
  6. For Video upload use C# code as

    var uploadParams = new VideoUploadParams()
      {
        File = new FileDescription(@"dog.mp4"),
        ResourceType = "video"
        PublicId = "my_folder/my_sub_folder/my_dog",
        Overwrite = true,
        NotificationUrl = "http://mysite/my_notification_endpoint"
      };
      var uploadResult = cloudinary.Upload(uploadParams);

    The video will overwrite the existing my_dog video if it exists. When the video upload is complete, the specified notification URL will receive details about the uploaded media asset.

2
At:- 5/22/2018 1:50:32 PM
thanks for your perfect answer :), I can easily upload image on cloudinary in .NET after reading your answer 0
By : jon - at :- 5/25/2018 11:45:31 AM






Login/Register to answer
Or
Register directly by posting answer/details

Full Name *

Email *




By posting your answer you agree on privacy policy & terms of use