BackgroundTransferContentPart 类

定义

表示多部分传输请求的内容部分。 每个 BackgroundTransferContentPart 对象都可以表示文本内容的单个字符串或单个文件有效负载,但不能同时表示这两者。

public ref class BackgroundTransferContentPart sealed
/// [Windows.Foundation.Metadata.Activatable(Windows.Networking.BackgroundTransfer.IBackgroundTransferContentPartFactory, 65536, Windows.Foundation.UniversalApiContract)]
/// [Windows.Foundation.Metadata.Activatable(65536, Windows.Foundation.UniversalApiContract)]
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class BackgroundTransferContentPart final
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
/// [Windows.Foundation.Metadata.Activatable(65536, "Windows.Foundation.UniversalApiContract")]
/// [Windows.Foundation.Metadata.Activatable(Windows.Networking.BackgroundTransfer.IBackgroundTransferContentPartFactory, 65536, "Windows.Foundation.UniversalApiContract")]
class BackgroundTransferContentPart final
[Windows.Foundation.Metadata.Activatable(typeof(Windows.Networking.BackgroundTransfer.IBackgroundTransferContentPartFactory), 65536, typeof(Windows.Foundation.UniversalApiContract))]
[Windows.Foundation.Metadata.Activatable(65536, typeof(Windows.Foundation.UniversalApiContract))]
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class BackgroundTransferContentPart
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
[Windows.Foundation.Metadata.Activatable(65536, "Windows.Foundation.UniversalApiContract")]
[Windows.Foundation.Metadata.Activatable(typeof(Windows.Networking.BackgroundTransfer.IBackgroundTransferContentPartFactory), 65536, "Windows.Foundation.UniversalApiContract")]
public sealed class BackgroundTransferContentPart
function BackgroundTransferContentPart(name, fileName)
Public NotInheritable Class BackgroundTransferContentPart
继承
Object Platform::Object IInspectable BackgroundTransferContentPart
属性

Windows 要求

设备系列
Windows 10 (在 10.0.10240.0 中引入)
API contract
Windows.Foundation.UniversalApiContract (在 v1.0 中引入)
应用功能
internetClient internetClientServer privateNetworkClientServer

示例

以下示例演示如何配置和开始多部分上传操作。

var upload = null;
var promise = null;

function MultipartUpload (uriString, files) {
    try {

        var uri = Windows.Foundation.Uri(uriString);
        var uploader = new Windows.Networking.BackgroundTransfer.BackgroundUploader();
        var contentParts = [];
        files.forEach(function (file, index) {
            var part = new Windows.Networking.BackgroundTransfer.BackgroundTransferContentPart("File" + index, file.name);
            part.setFile(file);
            contentParts.push(part);
        });

        // Create a new upload operation.
        uploader.createUploadAsync(uri, contentParts).then(function (uploadOperation) {
            // Start the upload and persist the promise to be able to cancel the upload.
            upload = uploadOperation;
            promise = uploadOperation.startAsync().then(complete, error, progress);
        });
    } catch (err) {
        displayError(err);
    }
};

构造函数

BackgroundTransferContentPart()

创建 BackgroundTransferContentPart 对象。

BackgroundTransferContentPart(String)

创建一个 BackgroundTransferContentPart 对象,该对象标识它表示的内容。

BackgroundTransferContentPart(String, String)

创建一个 BackgroundTransferContentPart 对象,该对象标识文件内容及其表示的文件的名称。

方法

SetFile(IStorageFile)

为包含要上传的文件的 BackgroundTransferContentPart 设置源文件。

SetHeader(String, String)

设置内容处置标头值,该值指示此 BackgroundTransferContentPart 表示的信息的性质。

SetText(String)

使用此方法可设置 BackgroundTransferContentPart 表示的文本信息。

适用于

另请参阅