public void DeleteFile(string fileId) { if (!string.IsNullOrEmpty(fileId)) { if (MimeType.IsInGroups(fileId, MimeTypeGroups.Image, true)) { DeleteThumbnails(fileId); } var blob = Container.GetBlobClient(fileId); blob.DeleteIfExists(); } }
private static void UploadBlobFromStream(BlobClient blob, string fileName, string contentType, Stream source) { var uploadOptions = new BlobUploadOptions { HttpHeaders = CreateBlobHttpHeaders(contentType, fileName) }; if (MimeType.IsInGroups(contentType, MimeTypeGroups.Image)) { byte[] bytes = RotateFlipImageByOrientation(contentType, source); if (bytes != null) { blob.Upload(new BinaryData(bytes), uploadOptions); return; } } source.Position = 0; blob.Upload(source, uploadOptions); }
private void CopyTemporaryFiles(string directoryName, bool deleteTemporaryFiles) { var temporaryBlobItems = GetBlockBlobs(TemporaryContainer, directoryName + "/"); foreach (var tempBlobItem in temporaryBlobItems) { string fileName = GetNameFromFileId(tempBlobItem.Name); string blobName = GetFileId(fileName); var blob = Container.GetBlobClient(blobName); var tempBlob = TemporaryContainer.GetBlobClient(tempBlobItem.Name); if (MimeType.IsInGroups(tempBlobItem.Properties.ContentType, MimeTypeGroups.Image)) { Stream source = null; try { var downloadResult = tempBlob.DownloadContent().Value; source = downloadResult.Content.ToStream(); byte[] bytes = RotateFlipImageByOrientation(tempBlobItem.Properties.ContentType, source); if (bytes == null) { bytes = downloadResult.Content.ToArray(); } if (bytes != null) { var uploadOptions = new BlobUploadOptions { HttpHeaders = new BlobHttpHeaders { ContentType = tempBlobItem.Properties.ContentType, CacheControl = Settings.ClientCacheControl } }; blob.Upload(new BinaryData(bytes), uploadOptions); } } finally { source?.Dispose(); } DeleteThumbnails(blobName); } else { if (tempBlob.Exists()) { blob.StartCopyFromUri(tempBlob.Uri); } } if (deleteTemporaryFiles) { tempBlob.DeleteIfExists(); } } }