我使用Azure存储blob来存储图像,我试图在我的Xamrin.form应用程序中显示它。 我在github上找到了一个简单的教程和代码。
我已经成功通过遵循这些步骤来实现它,并在azure存储blob上创建一个帐户。
问题是:我可以看到文件的名称而不是“图像”
这是错误:
read started: <Thread Pool> #9 [0:] HTTP Request: Could not retrieve https://xxxxxx.blob.core.windows.net/yyyy/kakashi.jpg, status code NotFound [0:] ImageLoaderSourceHandler: Could not retrieve image or image data was invalid: Uri: https://lxxxxxx.blob.core.windows.net/yyyy/kakashi.jpg Thread finished: <Thread Pool> #4这是教程: 点击查看
这是Github: 点击查看
这是屏幕上的输出:
当我在我的bronwser上放置Urlof图像( https://lxxxxxx.blob.core.windows.net/yyyy/kakashi.jpg )时出现此错误:
This XML file does not appear to have any style information associated with it. The document tree is shown below. <Error> <Code>ResourceNotFound</Code> <Message> The specified resource does not exist. RequestId:97933c69-a01e-014f-6669-f0502e000000 Time:2018-05-20T18:33:28.4774584Z </Message> </Error>I am using Azure storage blob to store image and I am trying to display it in my Xamrin.form application. I have find a simple tutorial and the code on github.
I have succeed to implement it by following the steps and and create an account on azure storage blob.
The problem is : I can see the name of the file but not the "image"
here is the error:
read started: <Thread Pool> #9 [0:] HTTP Request: Could not retrieve https://xxxxxx.blob.core.windows.net/yyyy/kakashi.jpg, status code NotFound [0:] ImageLoaderSourceHandler: Could not retrieve image or image data was invalid: Uri: https://lxxxxxx.blob.core.windows.net/yyyy/kakashi.jpg Thread finished: <Thread Pool> #4Here is the tutorial: click to see
Here is the Github: click to see
Here is the output on screen:
and I have this error when I put the Urlof the image (https://lxxxxxx.blob.core.windows.net/yyyy/kakashi.jpg ) on my bronwser:
This XML file does not appear to have any style information associated with it. The document tree is shown below. <Error> <Code>ResourceNotFound</Code> <Message> The specified resource does not exist. RequestId:97933c69-a01e-014f-6669-f0502e000000 Time:2018-05-20T18:33:28.4774584Z </Message> </Error>最满意答案
1.请先检查您的订阅。
2.检查容器的访问策略。
3. 以下是保存并通过代码获取blob的步骤。
1)使用NuGet,我们可以安装所需的汇编包。 转到“管理解决方案菜单包”并搜索WindowsAzure.Storage和WindowsAzure.ConfigurationManager并单击“安装”。
2)获取配置中的访问密钥。
3)通过代码创建blob的示例代码:
public async Task<string> SaveImagesToAzureBlob(HttpPostedFileBase imageToUpload) { try { CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString")); CloudBlobClient cloudBlobClient = cloudStorageAccount.CreateCloudBlobClient(); CloudBlobContainer cloudBlobContainer = cloudBlobClient.GetContainerReference("sampleimage"); if (await cloudBlobContainer.CreateIfNotExistsAsync()) { await cloudBlobContainer.SetPermissionsAsync( new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob } ); } string imageFullPath = null; string imageName = Guid.NewGuid().ToString() + "-" + Path.GetExtension(imageToUpload.FileName); CloudBlockBlob cloudBlockBlob = cloudBlobContainer.GetBlockBlobReference(imageName); cloudBlockBlob.Properties.ContentType = imageToUpload.ContentType; await cloudBlockBlob.UploadFromStreamAsync(imageToUpload.InputStream); imageFullPath = cloudBlockBlob.Uri.ToString(); return imageFullPath; } catch (Exception ex) { throw ex; } }现在,检查您的存储帐户,您可以看到生成的容器样本。
默认情况下,容器将是私有的,没有人可以从外部访问。 要设置权限,我们应该使用SetPermission方法,如下所示。
CloudBlobContainer .SetPermissions(new BlobContainerPermissions {PublicAccess = BlobContainerPublicAccessType.Blob}); 请在列表中尝试不同的权限。
请注意权限级别设置。在您的情况下,它可能会导致问题。
有关详细信息:参考
https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-manager-deployment-model https://docs.microsoft.com/en-us/azure/storage/blobs/storage -dotnet-如何使用的二进制大对象
1.Please check your subscription first.
2.Check the access policy of your container.
3.Here is the steps to Save and get blobs through the code.
1)Using NuGet we can install required Assembly packages. Go to "Manage Package for Solution Menu" and search for WindowsAzure.Storage and WindowsAzure.ConfigurationManager and click on install.
2)Get access keys in the configuration.
3)Sample code to Create blob through the code:
public async Task<string> SaveImagesToAzureBlob(HttpPostedFileBase imageToUpload) { try { CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString")); CloudBlobClient cloudBlobClient = cloudStorageAccount.CreateCloudBlobClient(); CloudBlobContainer cloudBlobContainer = cloudBlobClient.GetContainerReference("sampleimage"); if (await cloudBlobContainer.CreateIfNotExistsAsync()) { await cloudBlobContainer.SetPermissionsAsync( new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob } ); } string imageFullPath = null; string imageName = Guid.NewGuid().ToString() + "-" + Path.GetExtension(imageToUpload.FileName); CloudBlockBlob cloudBlockBlob = cloudBlobContainer.GetBlockBlobReference(imageName); cloudBlockBlob.Properties.ContentType = imageToUpload.ContentType; await cloudBlockBlob.UploadFromStreamAsync(imageToUpload.InputStream); imageFullPath = cloudBlockBlob.Uri.ToString(); return imageFullPath; } catch (Exception ex) { throw ex; } }Now, check your storage account, you can see the container sample generated.
By default, the container will be private, no one can access from outside. To set the permissions we should use the SetPermission method as below.
CloudBlobContainer .SetPermissions( new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob }); Please try different permissions in the list.
Please note the permission level settings.In your case it may cause the issue.
For more details : Reference
https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-manager-deployment-model https://docs.microsoft.com/en-us/azure/storage/blobs/storage-dotnet-how-to-use-blobs
更多推荐
发布评论