user_50520
user_50520

Reputation: 37

Error while accessing the image directly using blob URL

I am new to Azure. I have activated my free subscription to learn Azure. I have created one Storage account in my portal. In that account, I created one container.

I uploaded an image to that container successfully. When I click that image, I have found the URL in properties that I can use to access via browser.

But I am getting below error while performing the above operation.

<Error>
<Code>ResourceNotFound</Code>
<Message>
The specified resource does not exist. RequestId:<Guid> Time:2022-05-17T11:20:46.2299517Z
</Message>
</Error>

But the image does exist in that container. Why am I getting the above error? How do I avoid that error?

Upvotes: 1

Views: 2094

Answers (2)

M M
M M

Reputation: 21

In my case, (I was receiving the same error), my container was public (blob), and all the access was set properly. My problem was that when I uploaded the images using the Azure.Storage.Blobs namespace, for example:

`
BlobContainerClient containerClient = new BlobContainerClient(blobcnnstr, containername);
using (MemoryStream stream = new MemoryStream(File.ReadAllBytes(filefullyqualifiedname)))
{
    containerClient.UploadBlob(filename, stream);
}
`

the image uploaded with a wrong CONTENT-TYPE. For images, content type needs to be "image/jpeg". When image is uploaded using Azure web site, the content type is set automatically to image/jpeg, however, when uploading programmatically, the content type is different (forgot what it was, something...stream). When I would modify the content type for a file manually, the URL started working magically.

So I used the following code to upload the files and set the correct content type.

`
using Azure.Storage.Blobs;
using Azure.Storage.Blobs.Models;

BlobContainerClient containerClient = new BlobContainerClient(blobcnnstr, containername);

BlobClient bc = containerClient.GetBlobClient(filename);

using (MemoryStream stream = new MemoryStream(File.ReadAllBytes(filefullyqualifiedname)))
{
    bc.Upload(stream, httpHeaders: new BlobHttpHeaders { ContentType = "image/jpeg" }, conditions: null);     
}
`

blobcnnstr variable contains the Storage Account Access Key connection string, containername variable contains container name, filename variable contains file name without the path, filefullyqualifiedname variable contains path + filename.

Hope this help someone.

Upvotes: 0

Sridevi
Sridevi

Reputation: 22637

I have tested in my environment. Please note that, when you are creating a new container, it's access level will be private by default.

Please check the access level of your container is Private or not like below:

Go to Azure Portal -> Storage Accounts -> Your Storage Account -> Containers -> Your Container "Public access level"

enter image description here

If that access level is private, when you access the blob of that container directly via browser, you will get error like below:

enter image description here

To change the access level of your container:

Select your container that enables Change Access level Option -> Select Change Access Level -> Select Blob or Container from the dropdown -> Click Ok

enter image description here

Now, access the blob URL directly via browser, there will be no issues.

Upvotes: 3

Related Questions