Share via


如何使用檔案服務,在適用於能源的 Azure 資料管理員中上傳檔案

您將在本文中,了解如何在適用於能源產業的 Microsoft Azure 資料管理員中使用檔案服務 API 上傳大型檔案 (~5GB)。 上傳流程牽涉到從檔案 API 擷取已簽署的 URL,然後使用已簽署的 URL,將檔案儲存至 Azure Blob 儲存體

產生已簽署的 URL

在 Azure Cloud Bash 中執行下列 curl 命令,為適用於能源產業的 Azure 資料管理員資源的指定資料分割,從檔案服務取得已簽署的 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 文件連結

步驟

  1. 使用此連結下載 azcopy

  2. 執行此命令以上傳檔案

    azcopy copy "<path_to_file>" "signed_url"
  1. 範例回應
    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 資料管理員,以開始旅程。