【问题标题】:Is there any REST API to check if blob exists in a container是否有任何 REST API 来检查容器中是否存在 blob
【发布时间】:2021-02-04 11:49:51
【问题描述】:

是否有任何 REST API 来检查容器中是否存在 blob?我知道我们可以使用 sdk 实现 tis,但我有一个要求,我需要通过 URI 和 SAS 令牌(使用 Powershell)进行检查。

【问题讨论】:

    标签: azure powershell azure-blob-storage


    【解决方案1】:

    通过使用 powershell 和 Rest API

    您必须使用 invoke-webrequest-method 头 你可以点击这个endpoint 您可以检查服务器响应 - 如果您收到指示 blob 不存在的 404

    如果 blob 存在,它将返回 blob 的标头。

    示例代码:

    try
    {
    Invoke-WebRequest -Method Head "https://svijaystorage.blob.core.windows.net/svijay-deploy/B.XML?sv=<SV>&st=2020-10-21T15:55:17Z&spr=https&sig=<SIG>" 
    }
    catch
    {
    if( $_.exception -like "*404*")
    {
    Write-Host "Blob Doesn't Exist" -ForegroundColor Yellow
    }
    }
    

    存在 blob 时的输出:

    blob 不存在时的输出:

    【讨论】:

    • @harshit - 我已经用示例代码更新了答案
    • $newUrl =https://.blob.core.windows.net//myblob.out ?sv=2019-07-07&sr=c&sig=XXXXXXXXXXXXXXXXXX&spr=https&se=2020 -10-30T11%3A00%3A00Z&sp=rwdl invoke-webrequest -method get $newUrl Error: Invoke-WebRequest: Bad Request Bad Request - Invalid URL HTTP 错误 400。请求 URL 无效。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-07-22
    • 1970-01-01
    • 2021-05-16
    • 1970-01-01
    • 2017-10-24
    • 1970-01-01
    • 2013-07-05
    相关资源
    最近更新 更多