你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
如何使用文件服务在 Azure Data Manager for Energy 中上传文件
本文介绍如何在 Microsoft Azure Data Manager for Energy 中使用文件服务 API 上传大型文件(约 5GB)。 上传过程涉及从文件 API 提取签名 URL,然后使用已签名 URL 将文件存储到Azure Blob 存储
生成已签名的 URL
在 Azure Cloud Bash 中运行以下 curl 命令,从文件服务中获取 Azure Data Manager for Energy 资源的给定数据分区的已签名 URL。
curl --location 'https://<URI>/api/file/v2/files/uploadURL' \
--header 'data-partition-id: <data-partition-id>' \
--header 'Authorization: Bearer <access_token>' \
--header 'Content-Type: text/plain'
示例请求
考虑名为“medstest”的 Azure Data Manager for Energy 资源,其数据分区名为“dp1”
curl --location --request POST 'https://medstest.energy.azure.com/api/file/v2/files/uploadURL' \
--header 'data-partition-id: medstest-dp1' \
--header 'Authorization: Bearer eyxxxxxxx.........................' \
--header 'Content-Type: text/plain'
示例响应
{
"FileID": "2c5e7ac738a64eaeb7c0bc8bd47f90b6",
"Location": {
"SignedURL": "https://dummy.bloburl.com",
"FileSource": "/osdu-user/1686647303778-2023-06-13-09-08-23-778/2c5e7ac738a64eaeb7c0bc8bd47f90b6"
}
}
然后,可以使用响应对象中的 SignedURL 密钥将文件上传到Azure Blob 存储
上传大小小于 5 GB 的文件
若要上传小于 5 GB 的文件大小,可以直接使用 PUT blob API 调用将其文件上传到Azure Blob 存储
示例 Curl 请求
curl --location --request PUT '<SIGNED_URL>' \
--header 'x-ms-blob-type: BlockBlob' \
--header 'Content-Type: <file_type>' \ # for instance application/zip or application/csv or application/json depending on file type
--data '@/<path_to_file>'
如果上传成功,我们会在响应中获取 201 Created
状态代码
上传大小大于或等于 5 GB 的文件
若要上传大小 >为 5 GB 的文件,需要 azcopy实用工具作为单个 PUT blob 调用不能大于 5 GB 文档链接
步骤
使用此链接下载
azcopy
运行以下命令以上传文件
azcopy copy "<path_to_file>" "signed_url"
- 示例响应
INFO: Could not read destination length. If the destination is write-only, use --check-length=false on the command line.
100.0 %, 1 Done, 0 Failed, 0 Pending, 0 Skipped, 1 Total
Job 624c59e8-9d5c-894a-582f-ef9d3fb3091d summary
Elapsed Time (Minutes): 0.1002
Number of File Transfers: 1
Number of Folder Property Transfers: 0
Number of Symlink Transfers: 0
Total Number of Transfers: 1
Number of File Transfers Completed: 1
Number of Folder Transfers Completed: 0
Number of File Transfers Failed: 0
Number of Folder Transfers Failed: 0
Number of File Transfers Skipped: 0
Number of Folder Transfers Skipped: 0
TotalBytesTransferred: 1367301
Final Job Status: Completed
后续步骤
通过将数据引入 Azure Data Manager for Energy 资源来开始旅程。