【问题标题】:Azure Storage : how to upload/add word document/csv into file share using Rest APIAzure 存储:如何使用 Rest API 将 word 文档/csv 上传/添加到文件共享中
【发布时间】:2021-11-05 16:17:45
【问题描述】:

我刚开始使用 Azure 存储帐户(请耐心等待)。

我有一个要求,我必须上传文档(特别是 .docx、.txt 和 .csv。

为此,我创建了 Azure 存储帐户并添加了文件共享。随后,我生成了 SAS 令牌。

我的存储帐户是公开可用的,并且网络选项卡已选择所有网络。

现在,我尝试使用 REST API 上传我的文档,这是我的邮递员代码 sn-p

PUT /sharedname/subdir/BlobTesting.txt HTTP/1.1
Host: mystorageaccount.file.core.windows.net
x-ms-type: file
x-ms-file-permission: inherit
x-ms-file-attributes: ReadOnly
x-ms-file-creation-time: now
x-ms-file-last-write-time: now
x-ms-content-length: 102
Date: Wed, 08 Sep 2021 23:23:20 GMT
Authorization: SharedKey mystorageaccount: xxxxxxxx
x-ms-version: 2020-04-08

我收到以下错误消息

    <?xml version="1.0" encoding="utf-8"?>
    <Error>
        <Code>InvalidAuthenticationInfo</Code>
        <Message>Authentication information is not given in the correct format. Check the value of Authorization header.
    RequestId:155df990-401a-007e-4d09-a5aba4000000
    Time:2021-09-08T23:31:50.5455929Z</Message>
    </Error>

另外,我想知道如何上传文件的内容以及我没有找到任何具体方法的文档。

请有人帮忙。

谢谢

【问题讨论】:

  • 如果您使用共享访问签名,则不需要 AuthorizationDate 标头。您的请求 URL 应类似于 https://account.file.core.windows.net/sharedname/subdir/BlobTesting.txt?sastoken。您可以通过删除这两个标头来重试吗?

标签: azure azure-storage azure-blob-storage


【解决方案1】:

我已经在我的环境中测试过了。

请使用以下邮递员代码 sn-p :

PUT https:// mystorageaccount.file.core.windows.net/ /sharedname/subdir/BlobTesting.txt?sastoken
Headers : 
x-ms-content-length : maximum size for the file in bytes
x-ms-type : file
x-ms-file-permission : inherit
x-ms-file-attributes : ReadOnly
x-ms-file-creation-time : now
x-ms-file-last-write-time : now

文件已在存储帐户中成功创建:

参考:

https://docs.microsoft.com/en-us/rest/api/storageservices/create-file

【讨论】:

  • 我收到此错误 InvalidHeaderValue 其中一项的值HTTP 标头的格式不正确。 RequestId:107d60c2-201a-001a-1f5f-a55a3c000000 时间:2021-09-09T09:47:37.6854504ZContent-Length48
  • 现在我又添加了一个值为 0 的标头 Content-Length。我遇到了错误 AuthorizationResourceTypeMismatch 此请求无权使用此资源类型执行此操作。 RequestId:88163754-501a-003f-1b60-a5f340000000 时间:2021-09-09T09:50:37.1005049Z
  • 请使用以下标题:x-ms-content-length : 48 而不是 content-length : 48
  • 是的,我已经添加了,并且还添加了值为 0 的 Content-Length。现在错误消息是 AuthorizationResourceTypeMismatch 此请求无权使用此资源类型执行此操作。 RequestId:88163754-501a-003f-1b60-a5f340000000 时间:2021-09-09T09:50:37.1005049Z
  • 请删除 Content-Length: 0 标头并尝试
猜你喜欢
  • 2020-09-17
  • 2018-08-09
  • 2020-11-17
  • 2020-02-13
  • 2018-12-16
  • 2016-09-15
  • 2018-10-16
  • 2020-11-25
  • 1970-01-01
相关资源
最近更新 更多