【发布时间】:2017-03-30 15:00:54
【问题描述】:
如果我有一个随机 URL,我将如何检查它是否指向 Azure 中的 blob?如果它指向 Azure Blob,我可以确定该 Blob 存在并且我可以访问它。
我尝试了以下方法:
-
我用Exists做了一些测试,但不是很满意:
new CloudBlockBlob(new Uri("http://example.com")) ArgumentException: Invalid blob address 'http://example.com/', missing container information new CloudBlockBlob(new Uri("https://example.com/fdh/3746C9A2-533E-4544-A10B-321A8BC40AEA/sample-file.txt")).Exists() false new CloudBlockBlob(new Uri("http://stackoverflow.com/questions/43109843/ways-to-migrate-documents-pdf-forms-from-ms-sharepoint-to-aem")).Exists() StorageException: Blob type of the blob reference doesn't match blob type of the blob.所以基本上创建
CloudBlockBlob可能会失败,Exists可能会失败或返回false。但这样做感觉不对。
我可以检查 url 是否为
https://<storage-account>.blob.core.windows.net/<container>/*,但我不确定这是否总是正确的。
如果我能保证 2. 有效,我会这样做,因为不需要 HTTP 请求。
是否有其他(更好的)方法来检查随机 URL 是否指向 Azure 中的 blob(可能是(Azure 存储 SDK)框之外的东西)?
【问题讨论】:
-
可以选择网络请求吗?
-
是的,当然,任何请求都可以,只要它能完成工作。
-
如果它是私有容器和/或您没有指定正确的凭据,它也可能会失败
-
好的,如果我有一个指向 Azure Blob 的 URL,我可以确定它存在 并且我可以访问它(更新后的帖子)。
标签: c# azure azure-storage azure-blob-storage