在返回HttpClient
之前,如何检索fileStreamResult
携带的文件的大小
public async Task<FileStreamResult> Index(string id)
{
var urlToDownloadFromService= _upDownService.Downloadables.Find(d => d.Name == id);
HttpClient client = new HttpClient();
Stream stream = await client.GetStreamAsync(new Uri(urlToDownloadFromService.UrlSource));
var fileStreamResult = new FileStreamResult(stream, "application/octet-stream");
return fileStreamResult;
}
stream.Length
不起作用,因为ContentLengthReadStream
未实现该方法
更新
在dotnetcore框架中,HttpConnection
的实现像这样从response
对象获取长度信息
else if (response.Content.Headers.ContentLength != null)
{
long contentLength = Response.Content.Headers.ContentLength.GetValueOrDefault();
.
.
.
.
responseStream = new ContentLengthReadStream(this, (ulong)contentLength);