我正在上传图像并使用带有 DownloadData 的 WebClient 来获取字节数组,但现在它给我抛出了一个异常:
Exception: State size exceeded configured limit.
[File of type 'text/plain']
我以前从未注意到完全相同的图像的这种行为。可能出了什么问题?
private async Task SendPhoto_ActivityReceivedAsync(IDialogContext context, IAwaitable<object> result)
{
Activity activity = await result as Activity;
Activity activityReply = activity.CreateReply();
if (0 < activity.Attachments?.Count)
{
if (activity.Attachments.FirstOrDefault().ContentType.Equals("image/jpg") ||
activity.Attachments.FirstOrDefault().ContentType.Equals("image/jpeg") ||
activity.Attachments.FirstOrDefault().ContentType.Equals("image/png") ||
activity.Attachments.FirstOrDefault().ContentType.Equals("image/tiff"))
{
picImage = activity.Attachments.FirstOrDefault().Name;
HttpClient httpClient= new HttpClient();
picImageFile = await httpClient.GetByteArrayAsync(activity.Attachments.FirstOrDefault().ContentUrl);
await context.PostAsync("Want to send another?");
context.Wait(SendAnotherImage_ActivityReceivedAsync);
}
}
}
更新:将WebClient更改为HttpClient.GetByteArrayAsync,问题仍然存在。执行 PostAsync 后,该异常立即显示在机器人模拟器中
问题是picImageFile
是对话框内部的变量,因此由于对话框已序列化,因此它被保存在状态中。两个选项
- 下载映像并以该方法进行处理,而不将其保存在内存中
- 将字节数组保存在外部存储中。