0
votes

I used Azure blob to store images. I tested on local machine (with emulator) and it works. As you know, it uses URI like

http://127.0.0.1/xxx

But after I deployed to Azure, it doesn't work. I have

(1) changed the StorageConnectionString to point to Azure blob (instead of local emulated blob)

(2) changed blob access from 'off' to 'container'

(3) linked this blob to my website

I cannot think of anything else I need to do to make it work.

Can anyone help me?

Edit:

More information:

on local:

<add key="StorageConnectionString" value="DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1" />

on Azure:

<add key="StorageConnectionString" value="DefaultEndpointsProtocol=http;AccountName=[myAccount];AccountKey=[myKey];BlobEndpoint=http://[myBolbName].blob.core.windows.net/" />

The error on Azure is (when I click a button to upload an image):

Application: 2014-05-09T07:45:12  PID[22228] Error       Unable to connect to the remote server
Application:    at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync[T](RESTCommand`1 cmd, IRetryPolicy policy, OperationContext operationContext)
Application:    at Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob.UploadFromStreamHelper(Stream source, Nullable`1 length, AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext)
Application:    at xxx.Utility.AzureStorageAccess.UploadBlob(Stream stream, String containerName, String blobRelativeURI, String& blobURI)
Application:    at xxx.xxx.xxx.btnSubmit_Click(Object sender, EventArgs e)
2
You could help yourself by showing some code.John Saunders
If you're linking to images from your website, you might need to be looking at Azure CDNBrendan Green
@BrendanGreen - not sure why you're bringing up CDN - that has nothing to do with the question, as the question is not asking about optimizing latency of public blob access when clients are geo-distributed. The question (while poorly illustrated) is about the proper use of blob URI's.David Makogon
@martial - All you said is it doesn't work. We don't even know what that means. As John said: show your code. Show an actual URI you're using (masking out your unique namespace). Show the results, or error. Show something. As it stands, your question isn't answerable.David Makogon
@DavidMakogon: (3) linked this blob to my website. With no code demonstrating the issue, mentioning Azure CDN is not unreasonable.Brendan Green

2 Answers

2
votes

The URI to point to a blob in Storage is:

http://{accountName}.blob.core.windows.net/{container}/{blobName}

So, if your storage account is called marvin, the container is called images and the blob name is banner.png, the URI will be

http://marvin.blob.core.windows.net/images/banner.png

Note that unless you want people to be able to list the blobs within the container, you should set the public access level to blob, which makes the blobs visible but prevents operations on the container itself.

Also, for browsers to work correctly with the image, you'll need to ensure you've set the ContentType property on each blob to the correct MIME type, e.g. image/png.

1
votes

Thank Simon W for his comment, when I start to wrap the code with try and catch, I found the problem.

I have the following in my code:

CloudStorageAccount storageAccount = CloudStorageAccount.Parse("UseDevelopmentStorage=true");

I use this since I read somewhere that to make blob work in local, you need to use "UseDevelopmentStorage=true".

But this apparently doesn't work when deploy to Azure. So I have to replace it with:

CloudStorageAccount storageAccount = CloudStorageAccount.Parse([my-real-storage-connection-string]);

where [my-real-storage-connection-string] is

"DefaultEndpointsProtocol=http;AccountName=[myAccount];AccountKey=[myKey];BlobEndpoint=http://[myBolbName].blob.core.windows.net/"

This works.