/// <summary> /// Unlocks the BLOB item. This releases the lease on the server. /// If this method is not called on any locked item, it will naturally release when the lease expires. /// </summary> /// <param name="item">The item to release.</param> public async void UnlockBlob(IBlobItem item) { try { var tag = (CloudBlockBlob)item.Tag; var accessCondition = new AccessCondition { LeaseId = item.UniqueLeaseName }; await tag.ReleaseLeaseAsync(accessCondition); } catch (StorageException) { // Do nothing if lock did not exist (or file). } finally { // Check for a lock renewal timer and release it if it exists. if (LockTimers.ContainsKey(item)) { LockTimers[item]?.Dispose(); LockTimers.Remove(item); } } }
/// <summary> /// Creates smaller image sizes in blob store /// </summary> /// <param name="processType">Process type</param> /// <param name="blobHandle">Blob handle</param> /// <param name="imageType">Image type</param> /// <returns>Create image resizes task</returns> public async Task CreateImageResizes(ProcessType processType, string blobHandle, ImageType imageType) { this.log.LogInformation("resizing " + blobHandle); // retrieve the image from blob store IBlobItem imageBlob = await this.blobsStore.QueryImage(blobHandle); if (imageBlob.Stream == null || imageBlob.Stream.Length <= 0) { this.log.LogException("did not retrieve image " + blobHandle); } Image originalImage = Image.FromStream(imageBlob.Stream); // rotate the image originalImage = RotateImage(originalImage); // resize the image and store it in blob store List <ImageSize> imageSizes = null; if (ImageSizesConfiguration.Sizes.ContainsKey(imageType)) { imageSizes = ImageSizesConfiguration.Sizes[imageType]; } if (imageSizes != null) { foreach (ImageSize newSize in imageSizes) { await this.CreateResizedImage(blobHandle, originalImage, newSize); } } }
/// <summary> /// Downloads the BLOB from storage. /// </summary> /// <param name="blob">The BLOB item to download content for.</param> /// <returns><see cref="MemoryStream"/> containing BLOB content.</returns> public async Task <Stream> DownloadBlob(IBlobItem blob) { var stream = new MemoryStream(); await((CloudBlockBlob)blob.Tag).DownloadToStreamAsync(stream).ConfigureAwait(false); stream.Seek(0, SeekOrigin.Begin); return(stream); }
/// <summary> /// Adds metadata to the BLOB /// </summary> /// <param name="blob">The BLOB path.</param> /// <returns>Async Task</returns> public async Task UpdateBlobMetadata(IBlobItem blob) { if (!(blob is BlobItem item) || item.Tag == null) { return; } if (!(item.Tag is CloudBlockBlob cloudBlob)) { return; } await cloudBlob.SetMetadataAsync(); }
public async Task <IHttpActionResult> GetImage(string blobHandle) { string className = "ImagesController"; string methodName = "GetImage"; string logEntry = $"BlobHandle = {blobHandle}"; this.LogControllerStart(this.log, className, methodName, logEntry); bool exists = await this.blobsManager.ImageExists(blobHandle); if (!exists) { return(this.NotFound(ResponseStrings.ImageNotFound)); } IBlobItem blobItem = await this.blobsManager.ReadImage(blobHandle); logEntry += $", BlobType = {blobItem?.ContentType}, BlobContentLength = {blobItem?.Stream?.Length}"; this.LogControllerEnd(this.log, className, methodName, logEntry); return(new BlobResult(blobItem)); }
public async Task <IHttpActionResult> GetBlob(string blobHandle) { string className = "BlobsController"; string methodName = "GetBlob"; string logEntry = $"BlobHandle = {blobHandle}"; this.LogControllerStart(this.log, className, methodName, logEntry); bool exists = await this.blobsManager.BlobExists(blobHandle); if (!exists) { return(this.NotFound(ResponseStrings.BlobNotFound)); } IBlobItem blobItem = await this.blobsManager.ReadBlob(blobHandle); logEntry += $", {blobItem?.ContentType}"; this.LogControllerEnd(this.log, className, methodName, logEntry); return(new BlobResult(blobItem)); }
public static CloudBlockBlob GetBlob(IBlobItem item) { return(Storage.GetBlob(item.ContainerName, item.BlobName)); }
/// <summary> /// Initializes a new instance of the <see cref="BlobResult"/> class /// </summary> /// <param name="blob">blob to return in an http response</param> public BlobResult(IBlobItem blob) { this.blob = blob; }