/// <summary> /// Writes a stream to the blob. /// </summary> /// <param name="blobName">Virtual blob name.</param> /// <param name="blobStream">The <see cref="Stream"/> with data to be writen to the blob.</param> public virtual void WriteStream(string blobName, Stream blobStream) { blobName = blobName ?? throw new ArgumentNullException(nameof(blobName), nameof(CloudinaryStorageService)); blobStream = blobStream ?? throw new ArgumentNullException(nameof(blobStream), nameof(CloudinaryStorageService)); var blobInfo = BlobInfo.FromName(blobName); if (blobInfo == null) { throw new ArgumentException(nameof(CloudinaryStorageService), nameof(blobName)); } var rawUploadParams = new RawUploadParams(); rawUploadParams.File = new FileDescription(blobName, blobStream); rawUploadParams.PublicId = GetPublicId(blobName); var result = _client.Upload(rawUploadParams); }
public ActionResult Download(string blobName, string donloadFileLabel) { var blobInfo = BlobInfo.FromName(blobName); var blobStream = _blobService.Download(blobInfo); if (blobStream.IsNull()) { return(ErrorResult(HttpStatusCode.NotFound)); } var contentDisposition = new ContentDisposition { FileName = blobInfo.BuildDownloadFileName(donloadFileLabel), Inline = false }; Response.AppendHeader("Content-Disposition", contentDisposition.ToString()); return(File(blobStream, blobInfo.ContentType)); }
public Uri GetThumbEndpoint(string blobName, string label, int?width = null, int?height = null) { var blobInfo = BlobInfo.FromName(blobName); if (blobInfo == null) { return(null); } width = width ?? 0; height = height ?? 0; var instructions = new Instructions(); if (width > 0 && height > 0) { instructions.Width = width; instructions.Height = height; } else if (width > 0 || height > 0) { if (width > 0) { instructions.Width = width; } if (height > 0) { instructions.Height = height; } } else { instructions.Cache = ServerCacheMode.Always; } instructions.Mode = FitMode.Crop; return(GetThumbEndpoint(blobName, label, instructions)); }
public Uri GetThumbnailEndpoint(string blobName, string label, int?width = null, int?height = null) { var blobInfo = BlobInfo.FromName(blobName) ?? new BlobInfo("placeholder.png"); // ToDo: Cache verification. if (!_storageService.Exists(blobInfo.Name)) { label = (label?.First().ToString() ?? "?").ToUpper(); return(BuildUriBase64(blobInfo, label, width, height)); } if (!blobInfo.ContentType.Contains("image")) { var background = _configs.DefaultThumbBackgroundHexColor; var foreground = _configs.DefaultThumbForegroundHexColor; switch (blobInfo.Extension) { case "pdf": background = "#e81f01"; foreground = "#FFFFFF"; break; case "zip": background = "#FFE693"; foreground = "#afafaf"; break; } var docLabel = $".{blobInfo.Extension.Trim('.')}"; var thumbInfo = BlobInfo.FromName(blobInfo.GetThumbnailName()); return(BuildUriBase64(thumbInfo, docLabel, width, height, background, foreground)); } return(_thumbService.GetThumbEndpoint(blobName, label, width, height)); }
/// <summary> /// Get the endpoint to the blob within the storage service. /// </summary> /// <param name="blobName">Virtual blob name.</param> /// <returns>The <see cref="Uri"/> pointing to the bob file.</returns> public virtual Uri GetEndpoint(string blobName) { var blobInfo = BlobInfo.FromName(blobName); if (blobInfo == null) { return(null); } var contentType = blobInfo.ContentType; if (contentType.Contains("image")) { return(new Uri(_client.Api.UrlImgUp.CSubDomain(true).UseRootPath(true).BuildUrl(blobName), UriKind.Absolute)); } if (contentType.Contains("video")) { return(new Uri(_client.Api.UrlVideoUp.CSubDomain(true).UseRootPath(true).BuildUrl(blobName), UriKind.Absolute)); } return(new Uri(_client.Api.Url.CSubDomain(true).BuildUrl(blobName), UriKind.Absolute)); }
/// <summary> /// Get a endpoint to access the thumbnail picture. /// </summary> /// <param name="blobName">Virtual blob name.</param> /// <param name="label">A readable label to associate with the thumbnail.</param> /// <param name="width">The expected width or null for the full size.</param> /// <param name="height">The expected height or null for the full size.</param> /// <returns>A <see cref="Uri"/> pointing to the thumbnail picture.</returns> public Uri GetThumbEndpoint(string blobName, string label, int?width = null, int?height = null) { var blobInfo = BlobInfo.FromName(blobName); if (blobInfo == null) { return(null); } width = width ?? 0; height = height ?? 0; var transformation = new Transformation(); if (width > 0 && height > 0) { transformation = transformation.Width(width); transformation = transformation.Height(height); } else if (width > 0 || height > 0) { if (width > 0) { transformation = transformation.Width(width); } if (height > 0) { transformation = transformation.Height(height); } } transformation = transformation.Crop("fill"); transformation = transformation.Gravity("faces:center"); return(GetThumbEndpoint(blobName, label, true, transformation)); }