2 回答

TA貢獻1829條經(jīng)驗 獲得超7個贊
如果您使用 Base64 或 Byte[] 發(fā)送文件對象,那么它只允許限制可能高達 2-4 Mb,但如果您的圖像比它更大,它將不支持。
因此,解決方案是發(fā)布流內(nèi)容,例如,
var file = await CrossMedia.Current.PickPhotoAsync(new PickMediaOptions
{
PhotoSize = PhotoSize.Full,
CompressionQuality = 100
});
創(chuàng)建類似MediaFile的對象,public MediaFile AttachedImage;并將文件存儲到其中,這樣內(nèi)存流就不會丟失。喜歡,AttachedImage = file
API上的郵政編碼,
HttpClient httpClient = new HttpClient();
MultipartFormDataContent mt = new MultipartFormDataContent();
AttachedImage.GetStream().Position = 0;
StreamContent imagePart = new StreamContent(AttachedImage.GetStream());
imagePart.Headers.Add("Content-Type", ImageType);
mt.Add(imagePart, String.Format("file"), String.Format("bk.jpeg"));
requestMessage.Content = mt;
var response = await httpClient.PostAsync("Your URL", mt);
if (response.IsSuccessStatusCode)
{
var responseString = await response.Content.ReadAsStringAsync();
var objRootObjectuploadImage = JsonConvert.DeserializeObject<RootObjectuploadImage>(responseString);
if (objRootObjectuploadImage != null)
{
}
else
{
}
}
else
{
Loading(ActIndicator, false);
await DisplayAlert(res.LAlert, "webserver not responding.", res.LOk);
}
- 2 回答
- 0 關(guān)注
- 231 瀏覽
添加回答
舉報