public async Task <IFileInformation> CopyFileToSameServiceType(string identifier, IStorageService destinationService) { var destination = (AzureStorageService)destinationService; var uniqueName = Guid.NewGuid().ToString(); CloudBlockBlob sourceBlob = null; try { sourceBlob = BlobContainer.GetBlockBlobReference(identifier); await sourceBlob.AcquireLeaseAsync(null); var destinationBlob = destination.BlobContainer.GetBlockBlobReference(uniqueName); await destinationBlob.StartCopyAsync(sourceBlob); } finally { // Break the lease on the source blob. if (sourceBlob != null) { await sourceBlob.FetchAttributesAsync(); if (sourceBlob.Properties.LeaseState != LeaseState.Available) { await sourceBlob.BreakLeaseAsync(new TimeSpan(0)); } } } var info = new AzureFileInformation { StorageIdentifier = uniqueName }; return(info); }
public async Task <IFileInformation> StoreFile(Stream fileStream) { var uniqueName = Guid.NewGuid().ToString(); // try // { // uniqueName = uniqueName.ApplyExtension(name, contentType); // } // catch (Exception ex) // { // _logger.LogWarning(ex.Message); // } var blockBlob = BlobContainer.GetBlockBlobReference(uniqueName); await blockBlob.UploadFromStreamAsync(fileStream); var info = new AzureFileInformation { StorageIdentifier = uniqueName }; return(info); }