简体   繁体   English

如何 stream 来自 AWS S3 存储桶的预签名视频?

[英]How to stream a presigned video from an AWS S3 bucket?

When generating a presigned video URL from AWS S3 bucket the video will download in mp4 format if I use the URL in the web browser, however, it will not stream if I put it in the src attribute of a video tag. When generating a presigned video URL from AWS S3 bucket the video will download in mp4 format if I use the URL in the web browser, however, it will not stream if I put it in the src attribute of a video tag. Below is an example of what the presigned url looks like.下面是预签名的 url 的示例。 How can I use this url to stream?如何使用这个 url 到 stream?

<video width="320" height="240" controls preload="auto">
  <source src="https://s3.eu-north-1.amazonaws.com/daycare.videos/iland-guard/yamit/2020-12-09/cam_0/20201209_043123.mp4?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIA6OHOPCC5DWJXXO7O%2F20210309%2Feu-north-1%2Fs3%2Faws4_request&X-Amz-Date=20210309T075948Z&X-Amz-Expires=900&X-Amz-Signature=1cfb2dc7658b90714cd5b52b157f3caf878be6504a4d5f9d1a1be76a599abae8&X-Amz-SignedHeaders=host" type="video/mp4">
</video>

To test this, I did the following:为了测试这一点,我做了以下事情:

  • Put an .mp4 file in an Amazon S3 bucket (no Bucket Policy, no ACL).mp4文件放入 Amazon S3 存储桶(无存储桶策略,无 ACL)
  • Generated a pre-signed url using the AWS CLI aws s3 presign command使用 AWS CLI aws s3 presign命令生成了预签名的 url
  • Tested the pre-signed URL by pasting it into a browser Address Bar -- it worked通过将预签名的 URL 粘贴到浏览器地址栏中来测试它——它有效
  • Substituted the pre-signed URL in your code (above) -- it worked在您的代码(上图)中替换了预签名的 URL - 它有效

I did have a strange problem with a space in the filename -- I had to quote the path for the AWS CLI to include the raw space rather than using a + to represent the space.文件名中的空格确实有一个奇怪的问题——我必须引用 AWS CLI 的路径以包含原始空间,而不是使用+来表示空间。

The pre-signed URL that was generated looked like this:生成的预签名 URL 如下所示:

https://bucketname.s3.amazonaws.com/A2%20File.mp4?AWSAccessKeyId=AKIAxxx&Signature=xxx&Expires=1615413373

I see that it uses a different format to the one presented in your question.我看到它使用的格式与您的问题中提出的格式不同。

I replicated above, using the Node library.我使用 Node 库在上面进行了复制。 The code seems to work fine.该代码似乎工作正常。 The key thing to make sure is whether the presigned URL works when placed in your browser.要确保的关键是预签名的 URL 在您的浏览器中是否有效。 The SDK generates a URL regardless of whether the file exists or not, so make sure the presigned URL is actually functioning.无论文件是否存在,SDK 都会生成 URL,因此请确保预签名的 URL 实际运行。

The format of my presigned URL matches that of yours:我预签名的 URL 的格式与您的格式相匹配:

<video width="320" height="240" controls preload="auto">
    <source src="https://bucket.s3.ca-central-1.amazonaws.com/Glass%20one/2e71b368-1d22-4c56-a690-b534eea3def8.mp4?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=AKIAQOTARPS7GGSVO5F7%2F20210915%2Fca-central-1%2Fs3%2Faws4_request&X-Amz-Date=20210915T223104Z&X-Amz-Expires=3600&X-Amz-Signature=f61fc82b7ebd55ea83290587786d61fe41cb6137624d243bf36c46257ef2aab6&X-Amz-SignedHeaders=host&x-id=GetObject" type="video/mp4">
  </video>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM