Streaming a long video with AWS Presigned URL, problem with expiring links

huangapple go评论64阅读模式
英文:

Streaming a long video with AWS Presigned URL, problem with expiring links

问题

我正在流式传输一个长达1小时20分钟的视频,该视频托管在S3存储桶上,使用CloudFront生成预签名URL并将其插入到HTML视频标签的source属性中。我将过期时间设置为5分钟。

一切都运行正常。问题在于在某些情况下,视频会自行停止播放(在不同的位置,有时在第9分钟,有时在第18分钟,没有具体规律),并显示403禁止错误,显然是因为浏览器尝试检索更多数据,而链接已经过期。

有时,除非用户在链接过期后移动时间轴,否则根本不会停止,但始终会出现相同的错误。

在这种情况下,生成链接的正确方式是什么?我希望用户能够在链接过期后仍然能够在视频中移动时间轴,只要连接仍然有效,尤其是我不希望视频在一段时间后因过期而自行停止播放,但首次访问链接应在5分钟后过期。

在这个问题上似乎找不到任何相关信息。

感谢任何帮助!

英文:

Im streaming a long (1:20 hours) video that is hosted in an S3 bucket with cloudfront, by generating a presigned url and inserting it in the source property of an html video tag. I set the expiration time to 5 minutes.

everything works fine. the problem is in some cases the video stops on its own (in various places, sometime at minute 9, sometime 18. nothing specific) with a 403 Forbidden error, obvoiusly because the browser is trying to retrieve more data and the link was already expired.

sometimes its not stopping at all unless the user moves the time bar around after the link expired, getting the same error always.

what is the right way to generate the link in that use case? I want users to be able to move the time bar around in the video even after the expiration time, as long as the connection is alive, and especially I dont want the video to stop on its own after a while because it expired, but addressing the link for the first time should expire after 5 minutes.

Don't seem to find any information on the matter.

thanks for any help!

答案1

得分: 1

只是一个猜测,也许你可以检查流量以进行验证

来自文档

CloudFront 何时检查已签名 URL 中的到期日期和时间?

CloudFront 在 HTTP 请求时检查已签名 URL 中的到期日期和时间。如果客户端在到期时间之前立即开始下载大文件,即使在下载过程中到期时间已过,下载也应该完成。如果 TCP 连接中断,客户端在到期时间之后尝试重新开始下载,下载将失败。

如果客户端使用 Range GET 来以较小的片段获取文件,任何在到期时间之后发生的 GET 请求都将失败。有关 Range GET 的更多信息,请参阅《CloudFront 如何处理对象的部分请求 (Range GET)》查看如何处理对象的部分请求 (Range GET)

英文:

Just a guess, maybe you can check the trafic to verify

From the docs:

When does CloudFront check the expiration date and time in a signed URL?

CloudFront checks the expiration date and time in a signed URL at the time of the HTTP request. If a client begins to download a large file immediately before the expiration time, the download should complete even if the expiration time passes during the download. If the TCP connection drops and the client tries to restart the download after the expiration time passes, the download will fail.

If a client uses Range GETs to get a file in smaller pieces, any GET request that occurs after the expiration time passes will fail. For more information about Range GETs, see How CloudFront processes partial requests for an object (range GETs)., see How CloudFront processes partial requests for an object (range GETs).

huangapple
  • 本文由 发表于 2023年2月8日 20:48:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/75386028.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定