我创建了.Net Core API + React Project,并尝试从Azure Blob存储流式传输视频文件,如以下代码所示。API 代码工作正常,但是当我播放视频文件时,我无法前进或后退视频计时。
我的 C# API 代码,
[AllowAnonymous]
[HttpGet("writetostreamfromblob")]
public async Task<FileContentResult> WriteToStreamFromBlob(string filename)
{
try
{
return await _documentsService.FielStreamFromBlob() ;
}
catch (Exception ex)
{
throw ex;
}
}
我的文档服务方法,
public async Task<FileContentResult> FielStreamFromBlob()
{
try
{
var cloudBlob = await _blobService.GetBlobAsync(PlatformServiceConstants._blobIntroductoryVideoContainerPath + PlatformServiceConstants.IntroductoryVideo1, introductoryvideocontainerName);
var fileStream = new MemoryStream();
MemoryStream memStream = new MemoryStream();
await cloudBlob.DownloadToStreamAsync(memStream);
return new FileContentResult (memStream.ToArray(), "application/octet-stream");
}
catch (Exception e)
{
throw e;
}
}
以及我的 React 或 HTML 代码来渲染文件内容,
<div className="content__area__container" style={{width:'50%',float:'right',marginTop:'100px'}}>
<video height="auto" controls style={{ width: '100%' }}>
<source src="documents/writetostreamfromblob?filename=Beach" type="video/mp4" />
</video>
</div>
视频播放没有任何错误,但无法开始或转发视频,我哪里出错了?这是.Net Core中正确的方法吗?
您需要将EnableRangeProcessing
属性设置为true
才能使其支持导航。
MemoryStream memStream = new MemoryStream();
await cloudBlob.DownloadToStreamAsync(memStream);
var result = FileContentResult (memStream.ToArray(), "application/octet-stream");
result.EnableRangeProcessing = true;
return result;