How to open blobs on browser without downloading through java service?

烂漫一生 提交于 2019-11-29 15:59:56

First thing you would want to check is the content-type property of the blob. In all likelihood, the content type of the blob would be application/octet-stream (which is the default content type). Because of this the browser is not understanding what to do with this blob and thus downloading it. Please try to change the content type of the blob to appropriate value (e.g. image/png) and that should fix the problem.

Also I noticed that you're setting the container's ACL to BlobContainerPublicAccessType.CONTAINER. If you're doing this, then there's no need for you to create Shared Access Signature (SAS). Your blobs will be accessible simply by their URL (https://accountname.blob.core.windows.net/containername/blobname). SAS comes into play when the container's ACL is Private.

Blobs have binary data which could be just about anything - an image, video, document etc. When you click on the blob url it's similar to clicking on any url that point's to a file. The default action of a browser would be to download the file unless the browser can display the contents.

What the comment (To view the uploaded blobs in a browser..) implies is that for the blob to be publicly visible you need to set appropriate permissions. Once these permissions are set you can paste the url to the blob in a browser and it would be accessible.

To allow public access to the container you can use the following code -

public static void SetPublicContainerPermissions(CloudBlobContainer 
container)
{
    BlobContainerPermissions permissions = container.GetPermissions();
    permissions.PublicAccess = BlobContainerPublicAccessType.Container;
    container.SetPermissions(permissions);
}

You can find more about managing access to blobs in the doucmentation

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!