public async Task <CopyFromUriOperation> CopyBlobFromUri(Uri source, string blobName, string containerName, CancellationToken cancellationToken = default) { BlobClient client = BlobStorageManager.GetBlobClient( azureStorageOptions: _azureStorageOptions, containerName: containerName, blobName: blobName); try { IDictionary <string, string> metaData = new Dictionary <string, string>(); metaData.Add(new KeyValuePair <string, string>("sourceFullUrl", source.AbsoluteUri)); metaData.Add(new KeyValuePair <string, string>("sourceFullPath", source.AbsolutePath)); return(await client.StartCopyFromUriAsync(source : source, metadata : metaData, cancellationToken : cancellationToken)); } catch (Exception ex) { throw new BlobServiceException( message: ex.Message, blobName: blobName, containerName: containerName, methodName: nameof(CopyBlobFromUri), innerException: ex); } }
public async Task <BlobContentInfo> UploadBlob(Stream objectStream, string blobName, string containerName, IDictionary <string, string> metaData, bool allowAnonymousRead = false, CancellationToken cancellationToken = default) { PublicAccessType publicAccessType = allowAnonymousRead ? PublicAccessType.Blob : PublicAccessType.None; BlobClient client = BlobStorageManager.GetBlobClient( azureStorageOptions: _azureStorageOptions, containerName: containerName, blobName: blobName, publicAccessType: publicAccessType); try { return(await client.UploadAsync( content : objectStream, metadata : metaData, cancellationToken : cancellationToken)); } catch (Exception ex) { throw new BlobServiceException( message: ex.Message, blobName: blobName, containerName: containerName, methodName: nameof(UploadBlob), innerException: ex); } }
public async Task <bool> UpdateBlobMetaData(string blobName, string containerName, IDictionary <string, string> metaData, CancellationToken cancellationToken = default) { BlobClient client = BlobStorageManager.GetBlobClient( azureStorageOptions: _azureStorageOptions, containerName: containerName, blobName: blobName); try { BlobProperties properties = await client.GetPropertiesAsync(cancellationToken : cancellationToken); IDictionary <string, string> existingMetaData = properties.Metadata; foreach (KeyValuePair <string, string> item in metaData) { if (existingMetaData.ContainsKey(item.Key)) { existingMetaData[item.Key] = item.Value; } else { existingMetaData.Add(item); } } Azure.Response <BlobInfo> response = await client.SetMetadataAsync(metadata : existingMetaData, cancellationToken : cancellationToken); return(response.GetRawResponse().Status == (int)HttpStatusCode.OK); } catch (Exception ex) { throw new BlobServiceException( message: ex.Message, blobName: blobName, containerName: containerName, methodName: nameof(UpdateBlobMetaData), innerException: ex); } }
public async Task <BlobSnapshotInfo> CreateBlobSnapshot(string blobName, string containerName, CancellationToken cancellationToken = default) { BlobClient client = BlobStorageManager.GetBlobClient( azureStorageOptions: _azureStorageOptions, containerName: containerName, blobName: blobName); try { return(await client.CreateSnapshotAsync(cancellationToken : cancellationToken)); } catch (Exception ex) { throw new BlobServiceException( message: ex.Message, blobName: blobName, containerName: containerName, methodName: nameof(CreateBlobSnapshot), innerException: ex); } }
public async Task <bool> DeleteBlobIfExists(string blobName, string containerName, CancellationToken cancellationToken = default) { BlobClient client = BlobStorageManager.GetBlobClient( azureStorageOptions: _azureStorageOptions, containerName: containerName, blobName: blobName); try { return(await client.DeleteIfExistsAsync(cancellationToken : cancellationToken)); } catch (Exception ex) { throw new BlobServiceException( message: ex.Message, blobName: blobName, containerName: containerName, methodName: nameof(DeleteBlobIfExists), innerException: ex); } }
public async Task <bool> SetBlobMetaData(string blobName, string containerName, IDictionary <string, string> metaData, CancellationToken cancellationToken = default) { BlobClient client = BlobStorageManager.GetBlobClient( azureStorageOptions: _azureStorageOptions, containerName: containerName, blobName: blobName); try { Azure.Response <BlobInfo> response = await client.SetMetadataAsync(metadata : metaData, cancellationToken : cancellationToken); return(response.GetRawResponse().Status == (int)HttpStatusCode.OK); } catch (Exception ex) { throw new BlobServiceException( message: ex.Message, blobName: blobName, containerName: containerName, methodName: nameof(SetBlobMetaData), innerException: ex); } }
public async Task <bool> AbortCopyBlobFromUri(string copyOperationId, string blobName, string containerName, CancellationToken cancellationToken) { BlobClient client = BlobStorageManager.GetBlobClient( azureStorageOptions: _azureStorageOptions, containerName: containerName, blobName: blobName); try { Azure.Response response = await client.AbortCopyFromUriAsync(copyId : copyOperationId, cancellationToken : cancellationToken); return(response.Status == (int)HttpStatusCode.OK); } catch (Exception ex) { throw new BlobServiceException( message: ex.Message, blobName: blobName, containerName: containerName, methodName: nameof(AbortCopyBlobFromUri), innerException: ex); } }
public async Task <bool> UndeleteBlob(string blobName, string containerName, CancellationToken cancellationToken = default) { BlobClient client = BlobStorageManager.GetBlobClient( azureStorageOptions: _azureStorageOptions, containerName: containerName, blobName: blobName); try { Azure.Response response = await client.UndeleteAsync(cancellationToken : cancellationToken); return(response.Status == (int)HttpStatusCode.OK); } catch (Exception ex) { throw new BlobServiceException( message: ex.Message, blobName: blobName, containerName: containerName, methodName: nameof(UndeleteBlob), innerException: ex); } }
public async Task <bool> DownloadBlobTo(Stream destination, string blobName, string containerName, CancellationToken cancellationToken = default) { BlobClient client = BlobStorageManager.GetBlobClient( azureStorageOptions: _azureStorageOptions, containerName: containerName, blobName: blobName); try { Azure.Response response = await client.DownloadToAsync(destination); return(response.Status == (int)HttpStatusCode.Created); } catch (Exception ex) { throw new BlobServiceException( message: ex.Message, blobName: blobName, containerName: containerName, methodName: nameof(DownloadBlobTo), innerException: ex); } }