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

DeviceUpdateClient.GetFileAsync 方法

定义

从版本获取特定的更新文件。

public virtual System.Threading.Tasks.Task<Azure.Response> GetFileAsync (string provider, string name, string version, string fileId, Azure.ETag? ifNoneMatch = default, Azure.RequestContext context = default);
abstract member GetFileAsync : string * string * string * string * Nullable<Azure.ETag> * Azure.RequestContext -> System.Threading.Tasks.Task<Azure.Response>
override this.GetFileAsync : string * string * string * string * Nullable<Azure.ETag> * Azure.RequestContext -> System.Threading.Tasks.Task<Azure.Response>
Public Overridable Function GetFileAsync (provider As String, name As String, version As String, fileId As String, Optional ifNoneMatch As Nullable(Of ETag) = Nothing, Optional context As RequestContext = Nothing) As Task(Of Response)

参数

provider
String

更新提供程序。

name
String

更新名称。

version
String

更新版本。

fileId
String

文件标识符。

ifNoneMatch
Nullable<ETag>

定义 If-None-Match 条件。 仅当服务器上的 ETag 与此值不匹配时,才会执行该操作。

context
RequestContext

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

返回

从服务返回的响应。 响应正文架构的详细信息位于下面的“备注”部分。

例外

providernameversionfileId 为 null。

providernameversionfileId 是空字符串,预期为非空。

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

示例

此示例演示如何使用所需参数调用 GetFileAsync 并分析结果。

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

Response response = await client.GetFileAsync("<provider>", "<name>", "<version>", "<fileId>");

JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement;
Console.WriteLine(result.GetProperty("fileId").ToString());
Console.WriteLine(result.GetProperty("fileName").ToString());
Console.WriteLine(result.GetProperty("sizeInBytes").ToString());
Console.WriteLine(result.GetProperty("hashes").GetProperty("<test>").ToString());

此示例演示如何使用所有参数调用 GetFileAsync,以及如何分析结果。

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

Response response = await client.GetFileAsync("<provider>", "<name>", "<version>", "<fileId>", null);

JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement;
Console.WriteLine(result.GetProperty("fileId").ToString());
Console.WriteLine(result.GetProperty("relatedFiles")[0].GetProperty("fileName").ToString());
Console.WriteLine(result.GetProperty("relatedFiles")[0].GetProperty("sizeInBytes").ToString());
Console.WriteLine(result.GetProperty("relatedFiles")[0].GetProperty("hashes").GetProperty("<test>").ToString());
Console.WriteLine(result.GetProperty("relatedFiles")[0].GetProperty("mimeType").ToString());
Console.WriteLine(result.GetProperty("relatedFiles")[0].GetProperty("scanResult").ToString());
Console.WriteLine(result.GetProperty("relatedFiles")[0].GetProperty("scanDetails").ToString());
Console.WriteLine(result.GetProperty("relatedFiles")[0].GetProperty("properties").GetProperty("<test>").ToString());
Console.WriteLine(result.GetProperty("downloadHandler").GetProperty("id").ToString());
Console.WriteLine(result.GetProperty("etag").ToString());
Console.WriteLine(result.GetProperty("fileName").ToString());
Console.WriteLine(result.GetProperty("sizeInBytes").ToString());
Console.WriteLine(result.GetProperty("hashes").GetProperty("<test>").ToString());
Console.WriteLine(result.GetProperty("mimeType").ToString());
Console.WriteLine(result.GetProperty("scanResult").ToString());
Console.WriteLine(result.GetProperty("scanDetails").ToString());
Console.WriteLine(result.GetProperty("properties").GetProperty("<test>").ToString());

注解

下面是响应有效负载的 JSON 架构。

响应正文:

UpdateFile架构:

{
              fileId: string, # Required. File identity, generated by server at import time.
              relatedFiles: [
                {
                  fileName: string, # Required. File name.
                  sizeInBytes: number, # Required. File size in number of bytes.
                  hashes: Dictionary<string, string>, # Required. Mapping of hashing algorithm to base64 encoded hash values.
                  mimeType: string, # Optional. File MIME type.
                  scanResult: string, # Optional. Anti-malware scan result.
                  scanDetails: string, # Optional. Anti-malware scan details.
                  properties: Dictionary<string, string>, # Optional. Optional file properties (not consumed by service but pass-through to device).
                }
              ], # Optional. Optional related files metadata used together DownloadHandler metadata to download payload file.
              downloadHandler: {
                id: string, # Required. Download handler identifier.
              }, # Optional. Optional download handler for utilizing related files to download payload file.
              etag: string, # Optional. File ETag.
              fileName: string, # Required. File name.
              sizeInBytes: number, # Required. File size in number of bytes.
              hashes: Dictionary<string, string>, # Required. Mapping of hashing algorithm to base64 encoded hash values.
              mimeType: string, # Optional. File MIME type.
              scanResult: string, # Optional. Anti-malware scan result.
              scanDetails: string, # Optional. Anti-malware scan details.
              properties: Dictionary<string, string>, # Optional. Optional file properties (not consumed by service but pass-through to device).
            }

适用于