I'm trying to connect to Azure media storage to upload files but I get the error every time I try to upload a file.
The error arises in the following section of the code:
var container = CloudStorageAccount.Parse(
ConfigurationManager.AppSettings["StorageConnectionString"]).CreateCloudBlobClient()
.GetContainerReference(ConfigurationManager.AppSettings["StorageContainerReference"]);
The application settings is as follows:
<appSettings>
<add key="webpages:Version" value="2.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="PreserveLoginUrl" value="true" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
<add key="StorageConnectionString" value="DefaultEndpointsProtocol=https;AccountName=mediasvczfpr6c9dg9jx2;AccountKey=+DlbXTjZG7bni9LOKaYOxqsxBxXVmzh7BpPzWByBi/Csl9XZ+VRcqMbZxuwcbDIg88o73+6M9ByVLwsHNNyLKQ==" />
<add key="CloudStorageContainerReference" value="temporary-media" />
<add key="StorageAccountKey" value ="+DlbXTjZG7bni9LOKaYOxqsxBxXVmzh7BpPzWByBi/Csl9XZ+VRcqMbZxuwcbDIg88o73+6M9ByVLwsHNNyLKQ==" />
<add key="StorageAccountName" value="mediasvczfpr6c9dg9jx2" />
<add key="MediaAccountName" value="azurevideoportal" />
<add key="MediaAccountKey" value="T2yMBqN0mk2O//cX+5RMYhqWOS3ekd0RJ3bLtTO5TgI=" />
</appSettings>
I fail to see why it won't connect to my azure storage since I'm using the same connection for a different project where it works fine.
The container variable is returned a null value so the error says:
Additional information: Value cannot be null.
This is just a simple variable naming error :)
In your line of code that's causing the exception, you are referencing the variable StorageContainerReference from your Web.config file. However, in your Web.config file, the variable is named CloudStorageContainerReference .
Try this instead, and it should help:
<appSettings>
<add key="webpages:Version" value="2.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="PreserveLoginUrl" value="true" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
<add key="StorageConnectionString" value="DefaultEndpointsProtocol=https;AccountName=mediasvczfpr6c9dg9jx2;AccountKey=+DlbXTjZG7bni9LOKaYOxqsxBxXVmzh7BpPzWByBi/Csl9XZ+VRcqMbZxuwcbDIg88o73+6M9ByVLwsHNNyLKQ==" />
<add key="StorageContainerReference" value="temporary-media" />
<add key="StorageAccountKey" value ="+DlbXTjZG7bni9LOKaYOxqsxBxXVmzh7BpPzWByBi/Csl9XZ+VRcqMbZxuwcbDIg88o73+6M9ByVLwsHNNyLKQ==" />
<add key="StorageAccountName" value="mediasvczfpr6c9dg9jx2" />
<add key="MediaAccountName" value="azurevideoportal" />
<add key="MediaAccountKey" value="T2yMBqN0mk2O//cX+5RMYhqWOS3ekd0RJ3bLtTO5TgI=" />
</appSettings>
From this line in your code
var container = CloudStorageAccount.Parse(
ConfigurationManager.AppSettings["StorageConnectionString"]).CreateCloudBlobClient()
.GetContainerReference(ConfigurationManager.AppSettings["StorageContainerReference"]);
I dont see anything in your AppSettings called StorageContainerReference . From the Azure docs themselves I see something like this as being the right way Link to Azure Docs
// Retrieve storage account from connection string.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
// Create the blob client.
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
// Retrieve a reference to a container.
CloudBlobContainer container = blobClient.GetContainerReference("ContainerName");
From your example could be because theres no settings by the name given or could be a fult in the StorageConnectionString setting
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.