使用wget或curl

时间:2016-04-28 23:55:09

标签: curl wget azure-storage-blobs

我知道我可以使用Azure CLI来实现这一目标,但我想使用常见的Linux / Unix命令。

我有一个Azure Blob容器,它是私有的。我们称之为https://my-account.blob.core.windows.net/my-blob-container/my-file.my-extension

如果我的容器设置为“仅对blob进行公共读取访问”,那么一切都很有效。

$ wget https://my-account.blob.core.windows.net/my-blob-container/my-file.my-extension
--2016-04-28 16:11:15-- https://my-account.blob.core.windows.net/my-blob-container/my-file.my-extension
Resolving my-account.blob.core.windows.net (my-account.blob.core.windows.net)... 4.11.2.14
Connecting to my-account.blob.core.windows.net (my-account.blob.core.windows.net)|4.11.2.14|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 21682 (21K) [application/octet-stream]
Saving to: ‘my-file.my-extension’

如果我的容器设置为“无公共访问”,并且我创建一个名为my-policy的访问策略,其读取/写入/删除/列表为一年,我会得到以下直接链接:{{1 }}

如果我将链接复制到浏览器中,文件会自动下载。如果我使用https://my-account.blob.core.windows.net/my-blob-container/my-file.my-extension?sv=2015-02-21&si=my-policy&sr=b&sig=y%2B2pvIuR9rGQdvm%2FQKp0xNCWE%2B1G%2F2IqjHkWMhRcPUA%3D,则会收到404错误:

wget

$ wget https://my-account.blob.core.windows.net/my-blob-container/my-file.my-extension?sv=2015-02-21&si=my-policy&sr=b&sig=y%2B2pvIuR9rGQdvm%2FQKp0xNCWE%2B1G%2F2IqjHkWMhRcPUA%3D [4] 14106 [5] 14107 [6] 14108 [2] Done si=my-policy [3] Done sr=b $ --2016-04-29 01:25:54-- https://my-account.blob.core.windows.net/my-blob-container/my-file.my-extension?sv=2015-02-21 Resolving my-account.blob.core.windows.net (my-account.blob.core.windows.net)... 4.11.2.14 Connecting to my-account.blob.core.windows.net (my-account.blob.core.windows.net)|4.11.2.14|:443... connected. HTTP request sent, awaiting response... 404 The specified resource does not exist. 2016-04-29 01:25:54 ERROR 404: The specified resource does not exist.. 返回退出统计数据8(“服务器发出错误响应”)。

1 个答案:

答案 0 :(得分:7)

如果没有具体细节,查询很难调试,但是......

我可以在容器级别创建一个SAS,允许我读取存储中的文件

wget "https://azurerpkg.blob.core.windows.net/azurer/doggies.jpg?st=2016-06-06T07%3A56%3A00Z&se=2018-06-07T07%3A56%3A00Z&sp=rl&sv=2015-04-05&sr=c&sig=nKQz5BcWoUaASBzSW7Hv0TzfMbTFcf0f%2B5mMtmTwQ2A%3D" -k -O "doggies.jpg"

如果我在blob级别创建一个特定的SAS,我的wget也能正常工作

wget "https://azurerpkg.blob.core.windows.net/azurer/doggies.jpg?st=2016-06-06T07%3A56%3A00Z&se=2018-06-07T07%3A56%3A00Z&sp=rl&sv=2015-04-05&sr=b&sig=ntNFXS6fUlHVkiqoqj2rHg1Pw6gSNosnYqj3CQ6GIrg%3D" -k -O doggies.jpg

有效的共享访问签名查询字符串需要以下参数的参数:

  • ST
  • SE
  • SR
  • SIG

您的似乎缺少se组件,即失效日期。

由于某些URL编码的性质,您必须确保在进行wget调用时将URL括在语音标记中