Code Monkey home page Code Monkey logo

cloudinary-dotnet's Introduction

cloudinary-dotnet

cloudinary-dotnet is a library to easily integrate Cloudinary into your ASP.net MVC projects. The library allows you to easily upload files to your Cloudinary cloud, and at the same time provides some Url and Html helpers to access your images.

WARNING: This library is OBSOLETE and replaced by an official Cloudinary library The official library can be found here on GitHub. It's probably more up to date already, and will be maintained on a more regular basis.

Installation

If you're not interested in the source and simply want to add Cloudinary to your project. Then there is a nuget package available. From the Package Manager Console, do:

    Install-Package Cloudinary

Uploading images

For uploading images you can use the Uploader class. It takes an AccountConfiguration instance (containing your cloud's name, api key and api secret) in the constructor. You can then use the the Upload to upload Images.

Example:

var configuration = new AccountConfiguration("your cloud name",
                                             "your api key",
                                             "your secret");

// Setup the uploader
var uploader = new Uploader(configuration);

string publicId = Path.GetFileNameWithoutExtension(filename);

using(var stream =new FileStream(filename, FileMode.Open))
{
 	// Upload the file
    var uploadResult = uploader.Upload(new UploadInformation(filename, stream)
                        {
						 	// explicitly specify a public id (optional)
                            PublicId = publicId,
							// set the format, (default is jpg)
                            Format = "png",
							// Specify some eager transformations														 
                            Eager = new[]
                                        {
                                            new Transformation(240, 240),
                                            new Transformation(120, 360) { Crop = CropMode.Limit },
                                        }
                        });

	// Write some output info	
    Console.WriteLine("Version: {0}, PublicId {1}", uploadResult.Version, uploadResult.PublicId);
    Console.WriteLine("Url: {0}", uploadResult.Url);
}
Console.WriteLine("Successfully uploaded file");

Creating Cloudinary Urls

In order to easily access your Cloudinary images, there are some UrlHelper extension methods. The easiest way to work with them, is when you first initialize the AccountConfiguration statically. That way, you can use the helper methods without needing the specify the AccountConfiguration object over and over.

For example, in your application startup routine, put the following method:

var configuration = new AccountConfiguration("your cloud name",
                                             "your api key",
                                             "your secret");

AccountConfiguration.Initialize(configuration);

Once that is done, you can call the CloudinaryImage extension methods without providing

<h3>Original</h3>
<img src="@Url.CloudinaryImage("sample")" alt="sample"/> 

<h3>Cropped 140x140</h3>
<img src="@Url.CloudinaryImage("sample", new Transformation(140, 140) { Crop = CropMode.Crop })" alt="cropped"/>

TODO's

This library is far from done, here are some things that are still on the TODO list

  • Correct creation of https urls
  • More tests
  • Uploading without reading the entire stream into memory

cloudinary-dotnet's People

Contributors

thomasvm avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.