public async Task <string> InsertFileAzureStorage(Evidence file, TypeData type, string containerName) { FileAzureDTO fileAzure = new FileAzureDTO(); CloudBlobContainer blobContainer = InitializeConexionAzure(containerName).Result as CloudBlobContainer; var blob = blobContainer.GetBlockBlobReference(file.FileName); blob.UploadFromByteArrayAsync(file.Bytes, 0, file.Bytes.Length, null, new BlobRequestOptions() { AbsorbConditionalErrorsOnRetry = true, RetryPolicy = new Microsoft.WindowsAzure.Storage.RetryPolicies.LinearRetry(TimeSpan.FromSeconds(20), 4) }, null).ContinueWith((res) => { if (res.IsCompletedSuccessfully) { fileAzure.FileName = blob.Name; fileAzure.Base64 = blob.Name.ToString(); fileAzure.Url = blob.Uri.AbsoluteUri; } else if (res.IsFaulted) { string errorAnswer = res.Exception.Message.ToString(); } }).Wait(); return(fileAzure.Url); }
public async Task <string> DeleteFileAzureStorage(Evidence file, string containerName) { try { FileAzureDTO fileAzure = new FileAzureDTO(); CloudBlobContainer blobContainer = InitializeConexionAzure(containerName).Result as CloudBlobContainer; CloudBlockBlob blob = blobContainer.GetBlockBlobReference(file.FileName); await blob.DeleteAsync().ContinueWith((res => { if (res.IsCompletedSuccessfully) { fileAzure.Url = blob.Uri.AbsoluteUri.ToString(); } else { fileAzure.Url = null; } })); return(fileAzure.Url); } catch (Exception ex) { return(ex.Message); } }
public async Task <string> InsertFileAzureStorage(Evidence file, string containerName) { try { FileAzureDTO fileAzure = new FileAzureDTO(); if (IsBase64String(file.Base64)) { CloudBlobContainer blobContainer = InitializeConexionAzure(containerName).Result as CloudBlobContainer; var blob = blobContainer.GetBlockBlobReference(file.FileName); var bytes = Convert.FromBase64String(RemoveAttributeBase64(file.Base64)); using (var stream = new MemoryStream(bytes)) { blob.UploadFromStreamAsync(stream, null, new BlobRequestOptions() { AbsorbConditionalErrorsOnRetry = true, RetryPolicy = new Microsoft.WindowsAzure.Storage.RetryPolicies.LinearRetry(TimeSpan.FromSeconds(20), 4) }, null).ContinueWith((res) => { if (res.IsCompletedSuccessfully) { fileAzure.FileName = blob.Name; fileAzure.Base64 = blob.Name.ToString(); fileAzure.Url = blob.Uri.AbsoluteUri; } else if (res.IsFaulted) { string errorAnswer = res.Exception.Message.ToString(); } }).Wait(); } return(fileAzure.Url); } else { return(null); } } catch (Exception ex) { return(ex.Message); } }