在c#中从Windows azure中删除blob

我有代码将blob插入存储,并允许用户查看blob列表和单个blob.但是,我现在无法删除blob,出现的错误是“System.ServiceModel.ni.dll中出现’System.ServiceModel.FaultException`1’类型的异常,但未在用户代码中处理.附...

我有代码将blob插入存储,并允许用户查看blob列表和单个blob.但是,我现在无法删除blob,出现的错误是

“System.ServiceModel.ni.dll中出现’System.ServiceModel.FaultException`1’类型的异常,但未在用户代码中处理.附加信息:远程服务器返回错误:(404)Not Found.”

WCF服务中的代码是

public void DeleteBlob(string guid, string uri)
{
    //create the storage account with shared access key
    CloudStorageAccount storageAccount = CloudStorageAccount.Parse(accountDetails);

    CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
    CloudBlobContainer container = blobClient.GetContainerReference(guid);

    CloudBlockBlob blob = container.GetBlockBlobReference(uri);
    blob.DeleteIfExists();
}

然后我通过SOAP服务在移动客户端应用程序中访问它,如:

private void mnuDelete_Click(object sender, EventArgs e)
{
    MessageBoxResult message = MessageBox.Show("Are you sure you want to delete this image?", "Delete", MessageBoxButton.OKCancel);
    if (message == MessageBoxResult.OK)
    {
        Service1Client svc = new Service1Client();
        svc.DeleteBlobCompleted += new EventHandler<AsyncCompletedEventArgs>(svc_DeleteBlobCompleted);
        svc.DeleteBlobAsync(container, uri);
    }
}
void svc_DeleteBlobCompleted(object sender, AsyncCompletedEventArgs e)
{
    if (e.Error == null) {
        NavigationService.Navigate(new Uri("/Pages/albums.xaml", UriKind.Relative));
    }
    else {
        MessageBox.Show("Unable to delete this photo at this time", "Error", MessageBoxButton.OK);
    }
}

我也首先使用SAS令牌来保存blob – 我不知道这是否有所作为?

解决方法:

在Azure Storage Client Library 4.0中,我们更改了Get * Reference方法以仅接受相对地址.因此,如果您使用的是最新的库且参数“uri”是绝对地址,则应将其更改为blob名称,或者应使用带有Uri和StorageCredentials对象的CloudBlockBlob constructor.

请查看我们GitHub repository中所有这些重大变化.

本文标题为:在c#中从Windows azure中删除blob

基础教程推荐