Reputation: 2517
I'm trying to upload an image from Server to Azure:
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(GLOBAL_AZURE.AZURE_STORAGE_CONNECTION_STRING);
CloudBlobContainer container = storageAccount.CreateCloudBlobClient().GetContainerReference("my-container");
CloudBlockBlob blockBlob = container.GetBlockBlobReference("my-img.jpg");
using (FileStream img = File.Open("d:\...\my-img.jpg",FileMode.Open))
{
blockBlob.UploadFromStream(img);
}
Everything works fine until UploadFromStream
throws:
"The remote server returned an error: (404) Not Found."
my-container
was created on the Portal and was defined "Public Blob".
Any ideas what might be the problem?
Upvotes: 2
Views: 2150
Reputation: 1594
This is caused if the container does not exist See this SO question as well getting 404 error when connecting to azure storage account
You can ensure the container exists by calling container.CreateIfNotExists()
prior to uploading the blob.
Personally I run this as part of some application start up code rather than on every blob upload.
This article has background https://azure.microsoft.com/en-gb/documentation/articles/storage-monitoring-diagnosing-troubleshooting/#the-client-is-receiving-404-messages
In the scenario where a client is attempting to insert an object, it may not be immediately obvious why this results in an HTTP 404 (Not found) response given that the client is creating a new object. However, if the client is creating a blob it must be able to find the blob container, if the client is creating a message it must be able to find a queue, and if the client is adding a row it must be able to find the table.
Upvotes: 5