我正在尝试将 Win 8 应用程序中的图像插入 Azure blob。当我尝试执行此操作时遇到 500 异常。这是我正在使用的课程 -
private MobileServiceCollection<TodoItem, TodoItem> items;
private IMobileServiceTable<TodoItem> todoTable = App.MobileService.GetTable<TodoItem>();
[DataContract]
public class TodoItem
{
[DataMember(Name = "id")]
public int ID { get; set; }
[DataMember(Name = "text")]
public string Text { get; set; }
[DataMember(Name = "containerName")]
public string ContainerName { get; set; }
[DataMember(Name = "resourceName")]
public string ResourceName { get; set; }
[DataMember(Name = "sasQueryString")]
public string SasQueryString { get; set; }
[DataMember(Name = "imageUri")]
public string ImageUri { get; set; }
}
异常在 -await todoTable.InsertAsync(todoItem); 行抛出 此时抛出异常,SASQueryString 的值为 NULL,ImageUri 为 NULL。
private async void OnTakePhotoClick(object sender, RoutedEventArgs e)
{
// Capture a new photo or video from the device.
CameraCaptureUI cameraCapture = new CameraCaptureUI();
media = await cameraCapture
.CaptureFileAsync(CameraCaptureUIMode.PhotoOrVideo);
TodoItem todoitem = new TodoItem { Text="NA",ContainerName="todoitemimages"};
InsertTodoItem(todoitem);
}
private async void InsertTodoItem(TodoItem todoItem)
{
string errorString = string.Empty;
if (media != null)
{
// Set blob properties of TodoItem.
todoItem.ResourceName = media.Name;
}
// Send the item to be inserted. When blob properties are set this
// generates an SAS in the response.
await todoTable.InsertAsync(todoItem);
// If we have a returned SAS, then upload the blob.
if (!string.IsNullOrEmpty(todoItem.SasQueryString))
{
// Get the new image as a stream.
using (var fileStream = await media.OpenStreamForReadAsync())
{
// Get the URI generated that contains the SAS
// and extract the storage credentials.
StorageCredentials cred = new StorageCredentials(todoItem.SasQueryString);
var imageUri = new Uri(todoItem.ImageUri);
// Instantiate a Blob store container based on the info in the returned item.
CloudBlobContainer container = new CloudBlobContainer(
new Uri(string.Format("https://{0}/{1}",
imageUri.Host, todoItem.ContainerName)), cred);
// Upload the new image as a BLOB from the stream.
CloudBlockBlob blobFromSASCredential =
container.GetBlockBlobReference(todoItem.ResourceName);
await blobFromSASCredential.UploadFromStreamAsync(fileStream.AsInputStream());
}
}
// Add the new item to the collection.
items.Add(todoItem);
}
无论如何我可以解决这个异常。谢谢。
These are the exception details -
Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException 未处理 HResult=-2146233079 消息=错误:内部服务器错误源=Microsoft.Threading.Tasks StackTrace:在 Microsoft.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)在 Microsoft.Runtime.CompilerServices。 Microsoft.Runtime.CompilerServices.TaskAwaiter.GetResult() 的 Microsoft.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(任务任务)的 TaskAwaiter.HandleNonSuccess(任务任务)。0.MoveNext() --- 从先前引发异常的位置结束堆栈跟踪 --- 在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)在 DeltaVMobile.CrudeStorageScenario.dc:\Users\~ 中的 _22.MoveNext() --- 从先前引发异常的位置结束堆栈跟踪 --- 在 System.Threading.WinRTSynchronizationContext 的 System.Runtime.CompilerServices.AsyncMethodBuilderCore.b__0(Object state)。 Invoker.InvokeCore() --- 从先前引发异常的位置结束堆栈跟踪 --- 在 System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object 的 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()状态,布尔值 preserveSyncCtx) 在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback 回调,对象状态,布尔值 preserveSyncCtx) 在 System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem。ExecuteWorkItem() 在 System.Threading.ThreadPoolWorkQueue.Dispatch() InnerException: