title: Upload text file to Azure blob Storage returns Internal Server Error
body: <p>I want to create an application, where the user can upload a text file to the Azure Blob Storage. I was using this example, but even this can't work for me: <a href="http://azure.microsoft.com/en-us/documentation/articles/mobile-services-windows-phone-upload-data-blob-storage/#install-storage-client" rel="nofollow">link</a></p>
  
  <p>I modified a little bit for my thing:</p>
  
  <pre><code>[DataContract]
  public class WorkoutItem
  {
  
      [JsonProperty(PropertyName = "id")]
      public string Id { get; set; }
  
      [JsonProperty(PropertyName = "containerName")]
      public string ContainerName { get; set; }
  
      [JsonProperty(PropertyName = "resourceName")]
      public string ResourceName { get; set; }
  
      [JsonProperty(PropertyName = "sasQueryString")]
      public string SasQueryString { get; set; }
  
      [JsonProperty(PropertyName = "filePath")]
      public string Filepath { get; set; }
  }
  </code></pre>
  
  <p>I want to upload a txt file, here is the method:</p>
  
  <pre><code>private async void InsertWorkoutItem(string localpath)
      {
          try
          {
              item = new WorkoutItem();
              string errorString = string.Empty;
  
              IsolatedStorageFileStream fileStream = IsolatedStorageFile.GetUserStoreForApplication().OpenFile(
                  localpath + ".txt", FileMode.Open, FileAccess.Read);
  
              if (fileStream != null)
              {
                  item.ContainerName = "workoutitemfiles";
                  item.ResourceName = localpath + ".txt";
              }
  
              await workouttable.InsertAsync(item); //exception thrown here
  
              if (!string.IsNullOrEmpty(item.SasQueryString))
              {
                  StorageCredentials cred = new StorageCredentials(item.SasQueryString);
                  var fileUri = new Uri(item.Filepath);
  
                  CloudBlobContainer container = new CloudBlobContainer(new Uri(
                      string.Format("https://{0}/{1}", fileUri.Host, item.ContainerName)), cred);
  
                  CloudBlockBlob blobFromSASCredential = container.GetBlockBlobReference(item.ResourceName);
                  await blobFromSASCredential.UploadFromStreamAsync(fileStream);
              }
          }
  </code></pre>
  
  <p>Exception details:</p>
  
  <pre><code>    {Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException: Error: Internal Server Error
     at Microsoft.WindowsAzure.MobileServices.MobileServiceHttpClient.&lt;ThrowInvalidResponse&gt;d__18.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
     at Microsoft.WindowsAzure.MobileServices.MobileServiceHttpClient.&lt;SendRequestAsync&gt;d__1d.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
     at Microsoft.WindowsAzure.MobileServices.MobileServiceHttpClient.&lt;RequestAsync&gt;d__4.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
     at Microsoft.WindowsAzure.MobileServices.MobileServiceTable.&lt;&gt;c__DisplayClass10.&lt;&lt;InsertAsync&gt;b__f&gt;d__12.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
     at Microsoft.WindowsAzure.MobileServices.MobileServiceTable.&lt;TransformHttpException&gt;d__41.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
     at Microsoft.WindowsAzure.MobileServices.MobileServiceTable.&lt;InsertAsync&gt;d__17.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
     at Microsoft.WindowsAzure.MobileServices.MobileServiceTable`1.&lt;TransformHttpException&gt;d__38.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
     at Microsoft.WindowsAzure.MobileServices.MobileServiceTable`1.&lt;InsertAsync&gt;d__b.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
     at Microsoft.WindowsAzure.MobileServices.MobileServiceTable`1.&lt;InsertAsync&gt;d__5.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
     at GPS_BLRM67.ViewModel.MainViewModel.&lt;InsertWorkoutItem&gt;d__c.MoveNext()}
  </code></pre>
  
  <p>Here is the StackTrace:</p>
  
  <pre><code>    at Microsoft.WindowsAzure.MobileServices.MobileServiceHttpClient.&lt;ThrowInvalidResponse&gt;d__18.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
     at Microsoft.WindowsAzure.MobileServices.MobileServiceHttpClient.&lt;SendRequestAsync&gt;d__1d.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
     at Microsoft.WindowsAzure.MobileServices.MobileServiceHttpClient.&lt;RequestAsync&gt;d__4.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
     at Microsoft.WindowsAzure.MobileServices.MobileServiceTable.&lt;&gt;c__DisplayClass10.&lt;&lt;InsertAsync&gt;b__f&gt;d__12.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
     at Microsoft.WindowsAzure.MobileServices.MobileServiceTable.&lt;TransformHttpException&gt;d__41.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
     at Microsoft.WindowsAzure.MobileServices.MobileServiceTable.&lt;InsertAsync&gt;d__17.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
     at Microsoft.WindowsAzure.MobileServices.MobileServiceTable`1.&lt;TransformHttpException&gt;d__38.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
     at Microsoft.WindowsAzure.MobileServices.MobileServiceTable`1.&lt;InsertAsync&gt;d__b.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
     at Microsoft.WindowsAzure.MobileServices.MobileServiceTable`1.&lt;InsertAsync&gt;d__5.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
     at GPS_BLRM67.ViewModel.MainViewModel.&lt;InsertWorkoutItem&gt;d__c.MoveNext()
  </code></pre>
  
  <p>Error on server-side:</p>
  
  <pre><code>Error in script '/table/WorkoutItem.insert.js'. Error: {"message":"The provided settings {\"blobendpoint\":\"http://undefined.blob.core.windows.net/\",\"tableendpoint\":\"http://undefined.blob.core.windows.net/\",\"queueendpoint\":\"http://undefined.blob.core.windows.net/\"} are not complete."}
  </code></pre>
  
  <p>Here is the server-side insert script:</p>
  
  <pre><code>    var azure = require('azure');
  var qs = require('querystring');
  var appSettings = require('mobileservice-config').appSettings;
  
  function insert(item, user, request) {
      // Get storage account settings from app settings. 
      var accountName = appSettings.STORAGE_ACCOUNT_NAME;
      var accountKey = appSettings.STORAGE_ACCOUNT_ACCESS_KEY;
      var host = accountName + '.blob.core.windows.net';
  
      if ((typeof item.containerName !== "undefined") &amp;&amp; (
      item.containerName !== null)) {
          // Set the BLOB store container name on the item, which must be lowercase.
          item.containerName = item.containerName.toLowerCase();
  
          // If it does not already exist, create the container 
          // with public read access for blobs.        
          var blobService = azure.createBlobService(accountName, accountKey, host);
          blobService.createContainerIfNotExists(item.containerName, {
              publicAccessLevel: 'blob'
          }, function(error) {
              if (!error) {
  
                  // Provide write access to the container for the next 5 mins.        
                  var sharedAccessPolicy = {
                      AccessPolicy: {
                          Permissions: azure.Constants.BlobConstants.SharedAccessPermissions.WRITE,
                          Expiry: new Date(new Date().getTime() + 5 * 60 * 1000)
                      }
                  };
  
                  // Generate the upload URL with SAS for the new image.
                  var sasQueryUrl = 
                  blobService.generateSharedAccessSignature(item.containerName, 
                  item.resourceName, sharedAccessPolicy);
  
                  // Set the query string.
                  item.sasQueryString = qs.stringify(sasQueryUrl.queryString);
  
                  // Set the full path on the new new item, 
                  // which is used for data binding on the client. 
                  item.filePath = sasQueryUrl.baseUrl + sasQueryUrl.path;
  
              } else {
                  console.error(error);
              }
              request.execute();
              item.userId=user.userId;
          });
      } else {
          request.execute();
      }
  }
  </code></pre>
  
  <p>What am I missing here? I've read in another thread that maybe the Windows Azure Storage reference is not added to the project, but that's not the problem for me.</p>