【问题标题】:Azure blob batch deletion failing to delete multiple file using rest APIAzure blob 批量删除无法使用 rest API 删除多个文件
【发布时间】:2022-01-02 20:35:01
【问题描述】:

我尝试通过 REST API 在 Azure blob 中进行批量删除。我已经创建了子请求

const test = `--batch_357de4f7-6d0b-4e02-8cd2-6361411a9525\r
Content-Type: application/http\r
Content-Transfer-Encoding: binary\r
\r
DELETE https://<accountName>.blob.core.windows.net/${azureDirectoryName}/${blobName} HTTP/1.1\r
Host: https://<accountName>.blob.core.windows.net\r
x-ms-date: ${strTime}\r
Authorization: Bearer ${authToken}\r
Content-Length: 0\r
--batch_357de4f7-6d0b-4e02-8cd2-6361411a9525--\r`

我在 nodeJs 中的请求对象是

{
   "url":"https://<accountName>.blob.core.windows.net/?comp=batch",
   "method":"POST",
   "headers":{
      "Content-Type":"multipart/mixed; boundary=END_OF_PART",
      "x-ms-date":"Wed, 24 Nov 2021 12:35:05 GMT",
      "x-ms-version":"2020-04-08",
      "Content-Length":10411,
      "Authorization":"Bearer <token>"
   },
   "body":"--END_OF_PART\r\nContent-Type: application/http\r\nContent-Transfer-Encoding: binary\r\n\r\nDELETE https://<account>.blob.core.windows.net/container/blob.txt\r\nx-ms-date: Wed, 24 Nov 2021 12:35:05 GMT\r\nAuthorization: Bearer <token>\r\nContent-Length: 0\r\n\r\n--END_OF_PART\r\nContent-Type: application/http\r\nContent-Transfer-Encoding: binary\r\n\r\nDELETE https://<accountName>.blob.core.windows.net/container/blob.txt\r\nx-ms-date: Wed, 24 Nov 2021 12:35:05 GMT\r\nAuthorization: Bearer <token>\r\nContent-Length: 0\r\n\r\n--END_OF_PART\r\nContent-Type: application/http\r\nContent-Transfer-Encoding: binary\r\n\r\nDELETE https://<accountName>.blob.core.windows.net/container/blob.txt\r\nx-ms-date: Wed, 24 Nov 2021 12:35:05 GMT\r\nAuthorization: Bearer <token>\r\nContent-Length: 0\r\n\r\n--END_OF_PART\r\nContent-Type: application/http\r\nContent-Transfer-Encoding: binary\r\n\r\nDELETE https://<accountName>.blob.core.windows.net/container/blob.txt\r\nx-ms-date: Wed, 24 Nov 2021 12:35:05 GMT\r\nAuthorization: Bearer <token>\r\nContent-Length: 0\r\n\r\n--END_OF_PART\r\nContent-Type: application/http\r\nContent-Transfer-Encoding: binary\r\n\r\nDELETE https://<accountName>.blob.core.windows.net/container/blob.txt\r\nx-ms-date: Wed, 24 Nov 2021 12:35:05 GMT\r\nAuthorization: Bearer <token>\r\nContent-Length: 0\r\n\r\n--END_OF_PART--"
}

我收到以下错误:

'--batchresponse_144e6c6b-2bbc-4f52-900e-d213906fac30
Content-Type: application/http

HTTP/1.1 400 One of the request inputs is not valid.
x-ms-error-code: InvalidInput
x-ms-request-id: requestId
x-ms-version: 2020-04-08
Content-Length: 221
Content-Type: application/xml
Server: Windows-Azure-Blob/1.0

<?xml version="1.0" encoding="utf-8"?>
<Error><Code>InvalidInput</Code><Message>One of the request inputs is not valid.
RequestId:requestId
Time:2021-11-24T12:46:45.4660320Z</Message></Error>
--batchresponse_144e6c6b-2bbc-4f52-900e-d213906fac30--'

【问题讨论】:

  • 您的子请求应该有主机名,它应该只有部分 URL。请参阅documentation 重新构建您的 http 请求正文。
  • 这个基础部分 'https://.blob.core.windows.net/ 不应出现在您的子请求中。

标签: azure rest azure-blob-storage


【解决方案1】:

谢谢Anand Sowmithiran。发布您的建议作为帮助其他社区成员的答案。

您的子请求不应包含主机名,而应仅包含部分 URL。

https://&lt;account&gt;.blob.core.windows.net/ 这个基础部分不应出现在您的sub-requests

可以参考Blob Batch - Request Body

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-08-26
    • 2021-09-24
    • 2021-02-02
    • 2021-09-22
    • 1970-01-01
    • 2021-04-19
    • 1970-01-01
    • 2016-08-06
    相关资源
    最近更新 更多