【发布时间】:2021-07-29 11:31:09
【问题描述】:
我有这个表格,其中有大约 10 个字段和最多 10 个图像。我将它们上传到服务器,大部分时间它都可以工作,但有时它会返回错误Error while copying content to a stream。
之后,当我重新启动应用程序并重试时,有时它可以工作,有时不能。
代码
// Image Path
var path_image_1 = await SecureStorage.GetAsync("image_1");
MultipartFormDataContent multiContent = new MultipartFormDataContent();
multiContent.Headers.ContentType.MediaType = "multipart/form-data";
// About 10 Fields like this
multiContent.Add(new StringContent(Email), "email");
// About 10 Images
var image_1 = File.ReadAllBytes(path_image_1);
multiContent.Add(new ByteArrayContent(image_1, 0, image_1.Count()), "images", path_image_1);
HttpClient httpClient = new HttpClient();
var response = await httpClient.PostAsync(url, multiContent);
string serverResponse = await response.Content.ReadAsStringAsync();
【问题讨论】:
-
上述设置存在许多潜在错误,无法从
Error while copying content to a stream推断出任何错误。网络连接可能有问题,另一端的侦听过程可能有问题,但侦听过程存储图像可能有问题,列表继续。 -
谢谢,你能分享一些资源吗?我的代码也正确吗?
-
您能否提供有关您的环境的更多信息?它的托管地点和方式等将有助于诊断潜在问题。