1

DeleteIfExists使用类中的方法时出现异常CloudBlockBlob

这是我的代码:

CloudBlobClient blobClient = this._storageAccount.CreateCloudBlobClient();

            directory = directory.ToLower();

            string containerDirectory = this.GetContainer(directory);
            string relativePathWithoutContainer = this.GetRelativePathWithoutContainer(directory);

            CloudBlobContainer container = blobClient.GetContainerReference(containerDirectory);
            container.CreateIfNotExist();
            container.SetPermissions(new BlobContainerPermissions() { PublicAccess = BlobContainerPublicAccessType.Blob });

            foreach (HttpPostedFileBase file in files)
            {
                CloudBlockBlob blob = container.GetBlockBlobReference(string.Format("{0}/{1}", relativePathWithoutContainer, file.FileName.ToLower()));
                blob.DeleteIfExists();
                blob.UploadFromStream(file.InputStream,new BlobRequestOptions());
            }

            return true;

我在这条线上遇到了异常:

blob.DeleteIfExists();

异常详情如下:

服务器未能验证请求。确保 Authorization 标头的值正确形成,包括签名。

4

1 回答 1

2

从这里得到一个例子尝试添加这些,看看它是否有效

// 如果 blob 已经存在,则删除它,同时删除所有快照。

BlobRequestOptions options = new BlobRequestOptions();

options.DeleteSnapshotsOption = DeleteSnapshotsOption.IncludeSnapshots;

blob.DeleteIfExists(options);
于 2013-01-13T06:33:53.273 回答