答案 0 :(得分:0)
您可以通过HttpClient通过api调用保存图像。这是代码:
将文件发送到API
var content = new ByteArrayContent(filedata);
content.Headers.ContentType = new MediaTypeHeaderValue(BE.Common.ContentType.appjson);
using (var client = new HttpClient())
{
aPIRequestfile.FileName = filename;
aPIRequestfile.UserId = CurrentSession.Instance.VerifiedUser.UserDetailId;
aPIRequestfile.ContentType = contentType;
aPIRequestfile.IsProfile = isProfile;
client.DefaultRequestHeaders.Add("FileDetails", JsonConvert.SerializeObject(aPIRequestfile));
var ApiRequest = client.PostAsync(apiUrl, content);
if (ApiRequest != null)
{
if (ApiRequest.Result.StatusCode == HttpStatusCode.OK)
{
RepsonseMsg = ApiRequest.Result.Content.ReadAsStringAsync().Result;
}
else
RepsonseMsg = BE.ResultStatus.Failed.ToString();
}
}
通过API接收
byte [] filebytes = Request.Content.ReadAsByteArrayAsync()。Result;
您将收到字节,然后可以保存它。