将视频文件流式传输为 'FileContentResult':无法 forward/backward 视频内容
Streaming video file as 'FileContentResult': Not able to forward/backward the video content
我创建了 .Net Core API + React 项目并尝试从 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;
我创建了 .Net Core API + React 项目并尝试从 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;