0

WFP 的新手,当我尝试上传到 Azure 存储 Blob 时出现错误:“Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment' 引发异常”。

有谁知道我为什么会收到这个错误?

private void btnUpload_Click(object sender, RoutedEventArgs e)
    {
        // Configure open file dialog box 
        Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
        dlg.FileName = "Picture"; // Default file name 
        dlg.DefaultExt = ".jpg"; // Default file extension 
        dlg.Filter = "JPEG Files (*.jpeg)|*.jpeg|PNG Files (*.png)|*.png|JPG Files (*.jpg)|*.jpg|GIF Files (*.gif)|*.gif"; // Filter files by extension 

        // Show open file dialog box 
        Nullable<bool> result = dlg.ShowDialog();

        // Process open file dialog box results 
        if (result == true)
        {
            // Open document 
            string logo = dlg.FileName;

斑点代码

     logo = Guid.NewGuid().ToString();

            // Retrieve storage account from connection string.
            CloudStorageAccount objStorage = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("DefaultEndpointsProtocol=https;AccountName=**;AccountKey=**=="));

            // Create the blob client.
            CloudBlobClient objclient = objStorage.CreateCloudBlobClient();

            // Retrieve a reference to a container.
            CloudBlobContainer objContainer = objclient.GetContainerReference("rewardsimageblob");

            // Create the container if it doesn't already exist.
            objContainer.CreateIfNotExist();

            // Retrieve reference to a blob named "uniqueBlobName"
            CloudBlob blob = objContainer.GetBlobReference(logo);

            // Create or overwrite the "uniqueBlobName" blob with contents from a local file.
            using (var fileStream = System.IO.File.OpenRead(@"path\myfile"))
            {
                blob.UploadFromStream(fileStream);
            }
4

1 回答 1

0

通过删除“RoleEnvironment.GetConfigurationSettingValue”错误消失了。

于 2013-08-01T16:32:22.997 回答