private async void UploadPicture_Click(object sender, RoutedEventArgs e) { await StorageBlob.UploadFileAsync(); if (StorageBlob._picture != null) { uploadMessage.Text = "Picture uploaded!"; } }
public IssuePage() { this.InitializeComponent(); LoadCustomersAsync().GetAwaiter(); LoadIssuesAsync().GetAwaiter(); LoadStatusAsync().GetAwaiter(); LoadCategoryAsync().GetAwaiter(); var connectionString = "YOUR_CONNECTION_String"; var containerName = "YOUR_CONTAINER_NAME"; StorageBlob.InitializeStorageAsync(connectionString, containerName).GetAwaiter(); }
public async Task <Stream> GetUploadedDoc(string docName = "Master Agreement_Template (1) (1)", string version = "1.0.0.1") { BlobStorageDetail blobStorageDetail = _DAO.GetDataLakeStorageDetails(); string storageConnectionString = string.Format("DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}", blobStorageDetail.StorageName, blobStorageDetail.StorageKey); var storageBlob = new StorageBlob(storageConnectionString, blobStorageDetail.FSContainerName); string filepath = storageBlob.Account.BlobStorageUri.PrimaryUri.AbsoluteUri + blobStorageDetail.FSContainerName + "/Techathon20/12/13/" + docName + "_v" + version + ".docx"; Stream file = await DataLakeHelper.GetFileStreamWithStorageBlob(storageBlob, filepath); //var parameters = ClientRequestParametersProvider.GetClientParameters(HttpContext, clientId); return(file); }
public static async Task <Stream> GetFileStreamWithStorageBlob(StorageBlob storageBlob, string reportFilePath) { try { // string filePath1 = @"https://devspendssdatalake.blob.core.windows.net/spendssintegration/351/Spend/10/3300/1/adbfiles/FieldWiseSummary/TestSpendErrorLogger.csv"; byte[] templateBytesArrayAspose = await storageBlob.DownloadBlobAsByteArray(reportFilePath); Stream fileStream = new MemoryStream(templateBytesArrayAspose); return(fileStream); } catch (Exception ex) { throw; } }
/// <summary> /// set blob meta /// </summary> /// <param name="azureBlob">ICloudBlob object</param> /// <param name="meta">meta data hashtable</param> private async Task SetBlobMeta(IStorageBlobManagement localChannel, StorageBlob.ICloudBlob blob, Hashtable meta) { if (meta == null) { return; } foreach (DictionaryEntry entry in meta) { string key = entry.Key.ToString(); string value = entry.Value.ToString(); if (blob.Metadata.ContainsKey(key)) { blob.Metadata[key] = value; } else { blob.Metadata.Add(key, value); } } AccessCondition accessCondition = null; StorageBlob.BlobRequestOptions requestOptions = RequestOptions; await Channel.SetBlobMetadataAsync(blob, accessCondition, requestOptions, OperationContext, CmdletCancellationToken); }
/// <summary> /// set blob properties /// </summary> /// <param name="azureBlob">ICloudBlob object</param> /// <param name="meta">blob properties hashtable</param> private async Task SetBlobProperties(IStorageBlobManagement localChannel, StorageBlob.ICloudBlob blob, Hashtable properties) { if (properties == null) { return; } foreach (DictionaryEntry entry in properties) { string key = entry.Key.ToString(); string value = entry.Value.ToString(); Action<StorageBlob.BlobProperties, string> action = validICloudBlobProperties[key]; if (action != null) { action(blob.Properties, value); } } AccessCondition accessCondition = null; StorageBlob.BlobRequestOptions requestOptions = RequestOptions; await Channel.SetBlobPropertiesAsync(blob, accessCondition, requestOptions, OperationContext, CmdletCancellationToken); }
/// <summary> /// upload file to azure blob /// </summary> /// <param name="taskId">Task id</param> /// <param name="filePath">local file path</param> /// <param name="blob">destination azure blob object</param> internal virtual async Task Upload2Blob(long taskId, IStorageBlobManagement localChannel, string filePath, StorageBlob.ICloudBlob blob) { string activity = String.Format(Resources.SendAzureBlobActivity, filePath, blob.Name, blob.Container.Name); string status = Resources.PrepareUploadingBlob; ProgressRecord pr = new ProgressRecord(OutputStream.GetProgressId(taskId), activity, status); DataMovementUserData data = new DataMovementUserData() { Data = blob, TaskId = taskId, Channel = localChannel, Record = pr }; BlobUploadJob uploadJob = new BlobUploadJob() { DestBlob = blob, SourcePath = filePath }; await this.RunTransferJob(uploadJob, data); if (this.BlobProperties != null || this.BlobMetadata != null) { await TaskEx.WhenAll( this.SetBlobProperties(localChannel, blob, this.BlobProperties), this.SetBlobMeta(localChannel, blob, this.BlobMetadata)); } try { await localChannel.FetchBlobAttributesAsync( blob, AccessCondition.GenerateEmptyCondition(), this.RequestOptions, this.OperationContext, this.CmdletCancellationToken); } catch (StorageException e) { //Handle the limited read permission. if (!e.IsNotFoundException()) { throw; } } WriteICloudBlobObject(data.TaskId, localChannel, blob); }