Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
blob当前是否具有SAS url?_Url_Azure_Asp.net Mvc 5_Azure Storage Blobs - Fatal编程技术网

blob当前是否具有SAS url?

blob当前是否具有SAS url?,url,azure,asp.net-mvc-5,azure-storage-blobs,Url,Azure,Asp.net Mvc 5,Azure Storage Blobs,我有一个MVC5互联网应用程序,可以将文件上传到Azure blob存储。我目前已经实现了为容器中的blob创建SAS的代码 我有一个MVC视图,它通过标记列出了许多不同对象的图像。每个图像都是相同的图像。我的意思是,它们具有相同的文件名,并且位于相同的容器中 是否可以检查blob是否已经有当前的SAS url,如果有,是否可以检索该SAS url 提前谢谢 编辑 以下是获取sas url的代码: public string GetBlobSasUri(string containerName,

我有一个MVC5互联网应用程序,可以将文件上传到Azure blob存储。我目前已经实现了为容器中的blob创建SAS的代码

我有一个MVC视图,它通过
标记列出了许多不同对象的图像。每个图像都是相同的图像。我的意思是,它们具有相同的文件名,并且位于相同的容器中

是否可以检查blob是否已经有当前的SAS url,如果有,是否可以检索该SAS url

提前谢谢

编辑

以下是获取sas url的代码:

public string GetBlobSasUri(string containerName, string fileName)
{
    CloudBlobContainer container = GetCloudBlobContainer(containerName);
    //Get a reference to a blob within the container.
    CloudBlockBlob blob = container.GetBlockBlobReference(fileName);

    //Set the expiry time and permissions for the blob.
    //In this case the start time is specified as a few minutes in the past, to mitigate clock skew.
    //The shared access signature will be valid immediately.
    SharedAccessBlobPolicy sasConstraints = new SharedAccessBlobPolicy();
    sasConstraints.SharedAccessStartTime = DateTime.UtcNow.AddMinutes(-5);
    sasConstraints.SharedAccessExpiryTime = DateTime.UtcNow.AddHours(4);
    sasConstraints.Permissions = SharedAccessBlobPermissions.Read;

    //Generate the shared access signature on the blob, setting the constraints directly on the signature.
    string sasBlobToken = blob.GetSharedAccessSignature(sasConstraints);

    //Return the URI string for the container, including the SAS token.
    return blob.Uri + sasBlobToken;
}

如果我传入带有
“Test”
容器名和带有
“Example.png”
文件名,则会创建并返回一个SAS。如果我随后将相同的参数传递到函数中,是否可以检查
文件名
是否已经为其创建了SAS,如果是,则返回相同的SAS url?

SAS是共享访问签名。这意味着——它只是识别给定资源的数字签名。它不会以任何方式附加到资源上。SAS不仅仅是分配给资源的随机生成的令牌。SAS在请求评估、签名检查、资源检查和操作检查期间进行验证。因此,服务本身(blob服务)和该服务中的资源(容器、blob)不知道SAS是否存在

已经说过,您有两种可能的方法:

  • 拥有存储SAS的缓存,其中缓存键将是您的blob URI。应针对SAS寿命配置适当的缓存到期时间
  • 为每个请求创建SA(以防无法关联请求)

这是MSDN文档。

您能解释一下您所说的
是什么意思吗?是否可以检查一个blob是否已经有了当前的SAS url
?您能看一下我的编辑吗?