Home > Software design >  How do I upload an image to cloudinary in ASP.NET MVC app?
How do I upload an image to cloudinary in ASP.NET MVC app?

Time:12-08

I'm using ASP.NET 4.7.2 MVC framework. I need to upload images using cloudinary and save the url of that image in my database. The problem is, Cloudinary's dot net documentation is a bit confusing as they have just declared a function. How do I make call to that function from my view? I have no idea.

Basically, I have a form and in there I want to add an option for uploading images (which should be done using cloudinary service) and then save the url of the uploaded image in my DB. I have no idea how to achieve that since their documentation only mentions just a function like so:

var uploadParams = new ImageUploadParams()
{
    File = new FileDescription(@"c:\my_image.jpg")
};
var uploadResult = cloudinary.Upload(uploadParams);

What do I do with this function and how to use it to add image uploading functionality? Please, help me out. Thanks.

CodePudding user response:

Uploading an asset to Cloudinary can be done either directly from the client-side (i.e., from the View of your application) or through the use of the server-side SDK (i.e., from the Controller of your application).

If you intend to perform the image uploading using the CloudinaryDotNet SDK (https://github.com/cloudinary/CloudinaryDotNet), you will need to submit the image file from the View back to the Controller of your application. And in the controller method, you can invoke the SDK methods to perform the actual image upload to Cloudinary server.

There is a sample project enclosed in the SDK source, which can be found in this link: https://github.com/cloudinary/CloudinaryDotNet/tree/master/samples.

  • Related