本文整理汇总了C#中CloudinaryDotNet.Actions.ImageUploadParams类的典型用法代码示例。如果您正苦于以下问题:C# ImageUploadParams类的具体用法?C# ImageUploadParams怎么用?C# ImageUploadParams使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ImageUploadParams类属于CloudinaryDotNet.Actions命名空间,在下文中一共展示了ImageUploadParams类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestAdHocParams
public void TestAdHocParams()
{
var breakpoint = new ResponsiveBreakpoint().MaxImages(5).BytesStep(20)
.MinWidth(200).MaxWidth(1000).CreateDerived(false);
ImageUploadParams uploadParams = new ImageUploadParams()
{
File = new FileDescription(m_testImagePath)
};
uploadParams.AddCustomParam("public_id", "test_ad_hoc_params_id");
uploadParams.AddCustomParam("tags", "test");
uploadParams.AddCustomParam("IgnoredEmptyParameter", "");
uploadParams.AddCustomParam("responsive_breakpoints", JsonConvert.SerializeObject(new List<ResponsiveBreakpoint> { breakpoint }));
uploadParams.AddCustomParam("IgnoredNullParameter", null);
var paramsDict = uploadParams.ToParamsDictionary();
Assert.AreEqual(3, paramsDict.Count);
Assert.IsFalse(paramsDict.ContainsKey("IgnoredEmptyParameter"));
Assert.IsFalse(paramsDict.ContainsKey("IgnoredNullParameter"));
ImageUploadResult result = m_cloudinary.Upload(uploadParams);
Assert.AreEqual(1, result.ResponsiveBreakpoints.Count);
Assert.AreEqual(5, result.ResponsiveBreakpoints[0].Breakpoints.Count);
Assert.AreEqual(1000, result.ResponsiveBreakpoints[0].Breakpoints[0].Width);
Assert.AreEqual(200, result.ResponsiveBreakpoints[0].Breakpoints[4].Width);
}
示例2: UploadTestResource
/// <summary>
/// A convenience method for uploading an image before testing
/// </summary>
/// <param name="id">The ID of the resource</param>
/// <returns>The upload results</returns>
private ImageUploadResult UploadTestResource( String id)
{
var uploadParams = new ImageUploadParams()
{
File = new FileDescription(m_testImagePath),
PublicId = id,
Tags = "test"
};
return m_cloudinary.Upload(uploadParams);
}
示例3: Store
public string Store(string name, Stream stream)
{
var upload = new ImageUploadParams {
File = new FileDescription(name, stream)
};
var result = cloudinary.Upload(upload);
return string.Format("{0}.{1}", result.PublicId, result.Format);
}
示例4: UploadImage
public bool UploadImage(string imgName,Stream img)
{
var uploadParams = new ImageUploadParams()
{
File = new FileDescription(imgName, img),
PublicId = imgName
};
var uploadResult = cloudinary.Upload(uploadParams);
//TODO: Дописать проверку на ошибку(не сохранилось ихображение)
return true;
}
示例5: UploadImage
public String UploadImage(String path)
{
var uploadParams = new ImageUploadParams()
{
File = new FileDescription(path),
};
var uploadResult = cloudinary.Upload(uploadParams);
if (uploadResult != null)
return uploadResult.Uri.AbsoluteUri;
else
return "";
}
示例6: CloudinaryUpload
/// <summary>
/// Method for uploading image from local host to cloudinary
/// </summary>
/// <param name="user"></param>
/// <returns>Cloudinary link(string) of uploaded picture</returns>
private string CloudinaryUpload(Models.RegisterBindingModel user)
{
var cloudPath = Server.MapPath(user.ProfileUrl);
Account acount = new Account("gigantor", "986286566519458", "GT87e1BTMnfLut1_gXhSH0giZPg");
Cloudinary cloudinary = new Cloudinary(acount);
var uploadParams = new ImageUploadParams()
{
File = new FileDescription(cloudPath)
};
var uploadResult = cloudinary.Upload(uploadParams);
string n = uploadResult.Uri.AbsoluteUri;
return user.ProfileUrl = n;
}
示例7: CloudinaryUpload
/// <summary>
/// Method for uploading image from local host to cloudinary
/// </summary>
/// <param name="user"></param>
/// <returns>Cloudinary link(string) of uploaded picture</returns>
private string CloudinaryUpload(Course course)
{
var cloudPath = System.Web.Hosting.HostingEnvironment.MapPath(course.PictureUrl);
Account acount = new Account("gigantor", "986286566519458", "GT87e1BTMnfLut1_gXhSH0giZPg");
Cloudinary cloudinary = new Cloudinary(acount);
var uploadParams = new ImageUploadParams()
{
File = new FileDescription(cloudPath)
};
var uploadResult = cloudinary.Upload(uploadParams);
string n = uploadResult.Uri.AbsoluteUri;
return course.PictureUrl = n;
}
示例8: UploadPhoto
public string UploadPhoto(Stream stream)
{
Account account = new Account(
CLOUD_NAME,
API_KEY,
API_SECRET);
Cloudinary cloudinary = new Cloudinary(account);
var uploadParams = new CloudinaryDotNet.Actions.ImageUploadParams()
{
File = new CloudinaryDotNet.Actions.FileDescription(Guid.NewGuid().ToString(), stream),
};
ImageUploadResult uploadResult = cloudinary.Upload(uploadParams);
return cloudinary.Api.UrlImgUp.BuildUrl(String.Format("{0}.{1}", uploadResult.PublicId, uploadResult.Format));
}
示例9: uploadImage
internal static String uploadImage(string filePath, string publicID)
{
//CloudinaryDotNet.Cloudinary cloudinary = new CloudinaryDotNet.Cloudinary();
//CloudinaryDotNet.Account account = new CloudinaryDotNet.Account("hmtca4hsp", "551419468127826", "6CRKqZzHmHxqCvpLaObNj2Hmsis");
CloudinaryDotNet.Account account = new CloudinaryDotNet.Account("hiisiwhue", "579971361974369", "bHspTdlzXHwF3uoLrEu5yb9a0b0");
CloudinaryDotNet.Cloudinary cloudinary = new CloudinaryDotNet.Cloudinary(account);
CloudinaryDotNet.Actions.ImageUploadParams uploadParams = new CloudinaryDotNet.Actions.ImageUploadParams()
{
File = new CloudinaryDotNet.Actions.FileDescription(filePath),//@"C:\Users\David\Downloads\etgarPlusWebsite-master\etgarPlusWebsite\etgarPlus\images\1.png"),
PublicId = publicID
};
CloudinaryDotNet.Actions.ImageUploadResult uploadResult = cloudinary.Upload(uploadParams);
string url = cloudinary.Api.UrlImgUp.BuildUrl(publicID + filePath.Substring(filePath.LastIndexOf(".")));
return url;
}
示例10: uploadImage
internal static String uploadImage(String filePath, String publicId)
{
CloudinaryDotNet.Account account = new CloudinaryDotNet.Account("hmtca4hsp", "551419468127826", "6CRKqZzHmHxqCvpLaObNj2Hmsis");
CloudinaryDotNet.Cloudinary cloudinary = new CloudinaryDotNet.Cloudinary(account);
CloudinaryDotNet.Actions.ImageUploadParams uploadParams = new CloudinaryDotNet.Actions.ImageUploadParams()
{
File = new CloudinaryDotNet.Actions.FileDescription(filePath),//@"C:\Users\David\Downloads\etgarPlusWebsite-master\etgarPlusWebsite\etgarPlus\images\1.png"),
PublicId = "4" //publicId
};
String url = cloudinary.Api.UrlImgUp.BuildUrl(publicId + filePath.Substring(filePath.LastIndexOf(".")));
Debug.WriteLine(url);
return url;
}
示例11: Save
/// <summary>
/// save an image to cloudinary
/// </summary>
/// <param name="stream">stream representing the image file to be saved</param>
/// <param name="fileName">name of the file</param>
/// <param name="tags">any tags to go with the image in cloudinary</param>
/// <returns></returns>
public ImageSaveResult Save(Stream stream, string fileName,string[] tags)
{
if (string.IsNullOrEmpty(fileName))
throw new ArgumentException("fileName parameter must be initilaised");
if(stream==null)
throw new ArgumentException("Stream parameter cannot be null");
using (stream)
{
stream.Seek(0, SeekOrigin.Begin); //go to the start of the stream
//the upload params are sent to cloudinary
var uploadParams = new ImageUploadParams {File = new FileDescription(fileName, stream)};
//get the tags in the right format for cloudinary upload
var tagString = ToTags(tags);
if (!string.IsNullOrEmpty(tagString))
uploadParams.Tags = tagString;
ImageUploadResult uploadResult;
try
{
uploadResult = _cloudinary.Upload(uploadParams); //upload the image and other details
}
catch (Exception ex)
{
return new ImageSaveResult { ErrorMessage = ex.Message, Error = true };
}
if (uploadResult.Error != null && uploadResult.Error.Message.Length > 0)
return new ImageSaveResult {ErrorMessage = uploadResult.Error.Message, Error = true};
return new ImageSaveResult
{
Error = false,
PublicID = uploadResult.PublicId,
SecureURL = _cloudinary.Api.UrlImgUp.BuildUrl(String.Format("{0}.{1}", uploadResult.PublicId, uploadResult.Format)),
ThumbnailURL = _cloudinary.Api.UrlImgUp.Transform(new Transformation().Width(70).Height(70).Radius("max").Crop("thumb").Gravity("face")).BuildUrl(String.Format("{0}.{1}", uploadResult.PublicId, uploadResult.Format)),
URL = uploadResult.Uri.AbsoluteUri
};
}
}
示例12: Add
public async Task<IEnumerable<Photo>> Add(HttpRequestMessage request)
{
var streamProvider = new MultipartMemoryStreamProvider();
await request.Content.ReadAsMultipartAsync(streamProvider);
List<Photo> photosSaved = new List<Photo>();
foreach (HttpContent ctnt in streamProvider.Contents)
{
using (Stream imageStream = await ctnt.ReadAsStreamAsync())
{
var uploadParams = new ImageUploadParams()
{
File = new FileDescription(ctnt.Headers.ContentDisposition.FileName, imageStream),
};
ImageUploadResult uploadResult = await _cloudinary.UploadAsync(uploadParams);
photosSaved.Add(new Photo { Uri = uploadResult.SecureUri.ToString() });
}
}
return photosSaved;
}
示例13: UploadImage
/// <summary>
/// Uploads the image.
/// </summary>
/// <param name="imageLink">The image link.</param>
/// <returns></returns>
public string UploadImage(string imageLink)
{
if (imageLink != null)
{
if (imageLink.StartsWith("http"))
{
return imageLink;
}
string pattern = "data:.*?base64,";
string base64string = Regex.Replace(imageLink, pattern, "");
Stream imageStream = new MemoryStream(Convert.FromBase64String(base64string));
var uploadParams = new ImageUploadParams
{
File = new FileDescription("Picture", imageStream)
};
var uploadResult = cloud.Upload(uploadParams);
if (uploadResult != null)
{
return uploadResult.Uri.AbsoluteUri;
}
}
return null;
}
示例14: UploadComplete
protected void UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
{
try
{
Account account = new Account("dlyvxs7of", "634626974285569", "FtB_0jhcmFypFS7QTwCBKcPRGzE");
Cloudinary cloudinary = new Cloudinary(account);
ImageUploadParams uploadParams = new ImageUploadParams()
{
File = new FileDescription("file", new MemoryStream(e.GetContents()))
};
ImageUploadResult uploadResult = cloudinary.Upload(uploadParams);
HEWDataContext context = new HEWDataContext();
context.ProjectsImages.InsertOnSubmit(new ProjectsImage
{ImgPublicID = uploadResult.PublicId, ProjectID = int.Parse(Request.QueryString["ProjectID"])});
context.SubmitChanges();
}
catch (Exception)
{
}
}
示例15: HandleFileUpload
private string HandleFileUpload(ref Photo photo)
{
string filePath = @"~\Images\defaultAccomodationPhoto.jpg";
if (Request.Files.Count > 0)
{
HttpPostedFileBase file = Request.Files[0];
if (file.ContentLength > 0 && _allowedTypes.Contains(file.ContentType))
{
try
{
using (var bitmap = new Bitmap(file.InputStream))
{
}
}
catch
{
ModelState.AddModelError("PhotoUrl", "The file type is not supported");
return "none";
}
string fileName = Path.GetFileName(file.FileName);
filePath = Path.Combine(@"~\Images\Photos", fileName);
string fullPath = Path.Combine(Server.MapPath(@"~\Images\Photos"), fileName);
file.SaveAs(fullPath);
Account account = new Account(
"bitbooking",
"131162311141994",
"yqy4VSrjuxaGeP8BUMgHwTozpfw");
Cloudinary cloudinary = new Cloudinary(account);
var uploadParams = new ImageUploadParams()
{
File = new FileDescription(fullPath)
};
var uploadResult = cloudinary.Upload(uploadParams);
FileInfo uploadedFileToServer = new FileInfo(fullPath);
uploadedFileToServer.Delete();
return uploadResult.Uri.AbsolutePath; //new photo URL from Cloudinary
}
else
{
if (file.ContentLength > 0 && !_allowedTypes.Contains(file.ContentType))
{
ModelState.AddModelError("PhotoUrl", "The file type is not supported");
return "none";
}
}
}
//photo.PhotoUrl = filePath;
return filePath;
}