Created
November 4, 2013 14:32
-
-
Save AlexShkor/7303317 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[POST] | |
public JsonResult UploadImage(HttpPostedFileBase uploadedFile) | |
{ | |
var cloudinary = new CloudinaryDotNet.Cloudinary(ConfigurationManager.AppSettings.Get("cloudinary_url")); | |
bool isValidImage; | |
if (uploadedFile != null) | |
{ | |
isValidImage = uploadedFile.IsValidImage(250, 250); | |
} | |
else | |
{ | |
// TODO: actions if close button pressed | |
return null; | |
} | |
if (isValidImage) | |
{ | |
uploadedFile.InputStream.Seek(0, SeekOrigin.Begin); | |
var uploadParams = new CloudinaryDotNet.Actions.ImageUploadParams() | |
{ | |
File = new CloudinaryDotNet.Actions.FileDescription("filename", uploadedFile.InputStream), | |
}; | |
var uploadResult = cloudinary.Upload(uploadParams); | |
string avatarUrl = cloudinary.Api.UrlImgUp.Transform(new CloudinaryDotNet.Transformation().Width(500).Height(500).Crop("limit")).BuildUrl(String.Format("{0}.{1}", uploadResult.PublicId, uploadResult.Format)); | |
return Json(new { avatarUrl = avatarUrl, avatarId = uploadResult.PublicId, avatarFormat = uploadResult.Format }); | |
} | |
return Json(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment