2
votes

I have an issue with accessing blob storage from an App Service Mobile App (Not MobileService). I previously have had a MobileService running that accessed the Blob Storage in the following way:

// Set the URI for the Blob Storage service.
Uri blobEndpoint = new Uri(string.Format("https://{0}.blob.core.windows.net", storageAccountName));

// Create the BLOB service client.
CloudBlobClient blobClient = new CloudBlobClient(blobEndpoint,
new StorageCredentials(storageAccountName, storageAccountKey));

Updating the code to work on the new service, still did not help. The dataconnection seems correct:

Therefore referring to these links azure configuration | azure connection string | azure get started blob storage.

I have extracted the data connection and have implemented the `MS_AzureStorageAccountConnectionString. I have the following methods to verify the correct access is found:

string tempstorage = "";
try
{
    CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("MS_AzureStorageAccountConnectionString"));
    tempstorage = storageAccount.BlobEndpoint.ToString() + "        " + storageAccount.BlobStorageUri.ToString();

    //Uri blobEndpoint = storageAccount.TableStorageUri.GetUri(StorageLocation.Primary);
}
catch
{
}
string cloud = "";
try
{
    CloudStorageAccount temp = CloudStorageAccount.DevelopmentStorageAccount;
    Uri endPoit = temp.BlobEndpoint;
    string uri = temp.BlobStorageUri.ToString();
    cloud = uri + "           " + endPoit.ToString();
 }
 catch
 {
 }
 return Ok("coud : " + cloud + "       temp storage : " + tempstorage);

return value:

coud : Primary = 'http://127.0.0.1:10000/devstoreaccount1'; Secondary = 'http://127.0.0.1:10000/devstoreaccount1-secondary' http://127.0.0.1:10000/devstoreaccount1 temp storage :

This shows the access is to the Storage emulator which is not desired.

Question

How to get the Uri for the Azure online storage such as to access it from the Azure app service.

Update based on the comment

I interpreted the request for cloud configuration as the application settings for the App Service on the azure portal.

<configuration>
     <connectionStrings>
         <add name="MS_AzureStorageAccountConnectionString" connectionString="DefaultEndpointsProtocol=https;AccountName=Name;AccountKey=key1_from_access_Keys" />
     </connectionStrings>
<configuration>
1
Sorry, not very clear. Could you please clarify, what you receive, what you need to receive? URIs seem correct.Alex Belotserkovskiy
@AlexBelotserkovskiy okay I will rewrite when I am at a pc. My question is that the URI scheme is completely different from Mobileservice. Why is this? Along the same lines the uri has devstoreaccount1 which isn't the name of the storage ? Is the URI because they exist in the same resourcegroup and therefore have local connection? (I can see that I was writing the question over too long time. I will rewrite, thank you for getting my attention pointed to this !)JTIM
Devstoreaccount is the local storage emulator. 127.0.0.1 as well. Check what you have in your cloud configuration - if you see devstirageaccount that means your project targets something localAlex Belotserkovskiy
Thanks! No worries - your information provided is helpful as well for troubleshooting.Alex Belotserkovskiy
You may be interested in a new feature that will generate SAS tokens for you for the client, and has a lot less manual code. It also works with offline sync, so you can queue blob uploads/downloads to when you have an active connection. See Connect to Azure Storage in your Xamarin.Forms app.lindydonna

1 Answers

1
votes

I tried to re-create the issue using your code, and that is what i done:

1) Click on the project => Add => Add Connected Service => Azure Storage => Select your storage account. That will install all of needed libraries and valid connection string into your web.config.

2) I copy-pasted your code into the HomeController Index action and was able to re-create the issue. Basically, looks like you changed the values and variables. The working code is below. The first snippet is for Controller, the second should be in the Index view. I used MVC, and you looks like using Web API, should not make any difference.

string tempstorage = "";
        string cloud = "";
        try
        {
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("allinazure_AzureStorageConnectionString"));
            cloud = storageAccount.BlobEndpoint.ToString() + "        " + storageAccount.BlobStorageUri.ToString();                
        }
        catch
        {
        }

        try
        {
            CloudStorageAccount temp = CloudStorageAccount.DevelopmentStorageAccount;
            Uri endPoit = temp.BlobEndpoint;
            string uri = temp.BlobStorageUri.ToString();
            tempstorage = uri + "           " + endPoit.ToString();
        }
        catch
        {
        }
     ViewBag.LocalStorage = "cloud storage" + cloud;
        ViewBag.CloudStorage = "local storage : " + tempstorage;

        return View();

Index view somewhere:

@ViewBag.LocalStorage
@ViewBag.CloudStorage

enter image description here