我有代码将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
基础教程推荐
- linux – 如何在Debian Jessie中安装dotnet core sdk 2023-09-26
- C# List实现行转列的通用方案 2022-11-02
- ZooKeeper的安装及部署教程 2023-01-22
- C# 调用WebService的方法 2023-03-09
- unity实现动态排行榜 2023-04-27
- C#类和结构详解 2023-05-30
- C# windows语音识别与朗读实例 2023-04-27
- C#控制台实现飞行棋小游戏 2023-04-22
- winform把Office转成PDF文件 2023-06-14
- 一个读写csv文件的C#类 2022-11-06