Upload a Single File to Blob Storage Azure

前端 未结 3 782
你的背包
你的背包 2020-12-05 04:35

How can I to Upload a file with C# ? I need to upload a file from a dialogWindow.

3条回答
  •  爱一瞬间的悲伤
    2020-12-05 05:06

    we can use BackgroundUploader class ,Then we need to provide StorageFile object and a Uri: Required Namespaces:

    using System;
    using System.Collections.Generic;
    using System.Threading;
    using System.Threading.Tasks;
    using Windows.Foundation;
    using Windows.Foundation.Collections;
    using Windows.Networking.BackgroundTransfer;
    using Windows.Storage.Pickers;
    using Windows.Storage;
    

    The process is Like This : Uri is defined using a string value provided via a UI input field, and the desired file for upload, represented by a StorageFile object, is returned when the end-user has selected a file through the UI provided by the PickSingleFileAsync operation

    Uri uri = new Uri(serverAddressField.Text.Trim());
    FileOpenPicker picker = new FileOpenPicker();
    picker.FileTypeFilter.Add("*");
    StorageFile file = await picker.PickSingleFileAsync();
    

    and Then:

    BackgroundUploader uploader = new BackgroundUploader();
    uploader.SetRequestHeader("Filename", file.Name);
    UploadOperation upload = uploader.CreateUpload(uri, file);
    
    // Attach progress and completion handlers.
    await HandleUploadAsync(upload, true);
    

    Thats All

提交回复
热议问题