我在asp.net网络应用程序接口框架中制作应用程序接口。我想读取文件,并将其转换为字节,并在读取文件时返回给client.But,发生异常,URL格式不受支持?带有fileName的URL是由客户端发送的。我想从这个URL中获取文件并将其转换为字节。告诉我,我是怎么做的?
[Route("api/product/v1/displayimage")]
[AllowAnonymous]
[HttpPost]
//[GZipCompression]
public async Task<byte[]> DisplayImage([FromBody] FilesVM model)
{
try
{
var UrlBase = Url.Content(model.BaseURL);
//var UrlBase = Url.Content("~/Images/Users/5-signs-march14");
// MemoryStream workStream = new MemoryStream();
//string contentType = MimeMapping.GetMimeMapping(fileName);
byte[] byteInfo = System.IO.File.ReadAllBytes(UrlBase);
return await Task.FromResult(byteInfo);
}
catch (Exception ex)
{
throw new HttpResponseException(HttpStatusCode.InternalServerError);
}
}
https://stackoverflow.com/questions/56065913
复制相似问题