yellowborat yellowborat - 5 months ago 8
HTML Question

Getting JSON file out in HTML through Azure Storage

I have hooked my Particle photon to a eventhub on Azure where i stream the data through Stream Analytics and then to my Azure Storage. Right now i recieve the temperature as a JSON file in Azure Storage.

Is there any way to do HTTP request or something to the storage account?
This is the JSON file:

Also, should i make a WepAPI that recieves theese data? so i also can make mobile app and not only webpage?


Yes, you may get the files out from the Azure Storage using the official SDKs. For that, you will need the Blob functionality - take a look here. And, if you want your own implementation, you can use the Azure Storage REST API.

 CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("ahrimanstoraccount_AzureStorageConnectionString"));
        CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
        CloudBlobContainer container = blobClient.GetContainerReference("vhds");
        CloudBlockBlob blockBlob = container.GetBlockBlobReference("yourfilename.txt");

        string path = (@"C:\Temp\yourlocalfilename.txt");
        blockBlob.DownloadToFile(path, FileMode.OpenOrCreate);


 <add key="ahrimanstoraccount_AzureStorageConnectionString" value="DefaultEndpointsProtocol=https;AccountName=myAccountName;AccountKey=myAccountKey" />

UPD from the comments: the same approach is working for Console and ASP.NET MVC. Azure Storage may be added by 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) Once it is done, the browser will open the page where code pieces will be shown and manually, by going to the Azure Storage page and copying keys/names to the connection string.