你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

DeviceUpdateClient.StartImportUpdateAsync 方法

定义

导入新的更新版本。 这是一个长时间运行的操作;使用Operation-Location响应标头值来检查操作状态。

public virtual System.Threading.Tasks.Task<Azure.Operation> StartImportUpdateAsync (Azure.WaitUntil waitUntil, Azure.Core.RequestContent content, Azure.RequestContext context = default);
abstract member StartImportUpdateAsync : Azure.WaitUntil * Azure.Core.RequestContent * Azure.RequestContext -> System.Threading.Tasks.Task<Azure.Operation>
override this.StartImportUpdateAsync : Azure.WaitUntil * Azure.Core.RequestContent * Azure.RequestContext -> System.Threading.Tasks.Task<Azure.Operation>
Public Overridable Function StartImportUpdateAsync (waitUntil As WaitUntil, content As RequestContent, Optional context As RequestContext = Nothing) As Task(Of Operation)

参数

waitUntil
WaitUntil

Completed 如果方法应在服务上完成长时间运行的操作之前等待返回,则为 ; Started 如果它在启动操作后应返回,则为 。 有关长时间运行的操作的详细信息,请参阅 Azure.Core Long-Running 操作示例

content
RequestContent

要作为请求正文发送的内容。 请求正文架构的详细信息,请参阅下面的“备注”部分。

context
RequestContext

请求上下文,它可以基于每个调用替代客户端管道的默认行为。

返回

表示 Operation 服务上的异步操作的 。

例外

content 为 null。

服务返回了不成功状态代码。

示例

此示例演示如何使用所需的参数和请求内容调用 StartImportUpdateAsync。

var credential = new DefaultAzureCredential();
var endpoint = new Uri("<https://my-service.azure.com>");
var client = new DeviceUpdateClient(endpoint, "<instanceId>", credential);

var data = new[] {
    new {
        importManifest = new {
            url = "<url>",
            sizeInBytes = 1234L,
            hashes = new {
                key = "<String>",
            },
        },
        friendlyName = "<friendlyName>",
        files = new[] {
            new {
                filename = "<filename>",
                url = "<url>",
            }
        },
    }
};

var operation = await client.StartImportUpdateAsync(WaitUntil.Completed, RequestContent.Create(data));

var response = await operation.WaitForCompletionResponseAsync();
Console.WriteLine(response.Status)

注解

下面是请求有效负载的 JSON 架构。

请求正文:

ImportUpdateInputItem架构:

{
              importManifest: {
                url: string, # Required. Azure Blob location from which the import manifest can be downloaded by Device Update for IoT Hub. This is typically a read-only SAS-protected blob URL with an expiration set to at least 4 hours.
                sizeInBytes: number, # Required. File size in number of bytes.
                hashes: Dictionary<string, string>, # Required. A JSON object containing the hash(es) of the file. At least SHA256 hash is required. This object can be thought of as a set of key-value pairs where the key is the hash algorithm, and the value is the hash of the file calculated using that algorithm.
              }, # Required. Import manifest metadata like source URL, file size/hashes, etc.
              friendlyName: string, # Optional. Friendly update name.
              files: [
                {
                  filename: string, # Required. Update file name as specified inside import manifest.
                  url: string, # Required. Azure Blob location from which the update file can be downloaded by Device Update for IoT Hub. This is typically a read-only SAS-protected blob URL with an expiration set to at least 4 hours.
                }
              ], # Optional. One or more update file properties like filename and source URL.
            }

适用于