从S3通过lambda加载a .mov视频
我正在尝试将.MOV视频文件加载到lambda Python脚本中进行处理。
import json
import urllib.parse
import boto3
import os
print('Loading function')
s3 = boto3.client('s3')
def lambda_handler(event, context):
# Get the object from the event and show its content type
bucket = os.environ['SOURCE_BUCKET_NAME']
key = urllib.parse.unquote_plus(event['Records'][0]['s3']['object']['key'], encoding='utf-8')
try:
video = s3.get_object(Bucket=bucket, Key=key)
print(video)
return event
except Exception as e:
print(e)
print('Error getting object {} from bucket {}. Make sure they exist and your bucket is in the same region as this function.'.format(key, bucket))
raise e
“视频”对象内编码是一个字典,包含一个带有值'< botocore.response.streamingbody对象的“正文”键,位于0x7f0c0d4ec310'。我已经尝试了多种读取此内容的方法,包括:
video = video ['body']。read()
返回字节。当我尝试读取带有打开(...)或字节的字节时,我会发现错误:“ Endswith首先必须是字节或字节元组,而不是str”。
我还尝试了
video ['hody']。
video = 。
I am trying to load a .mov video file into a Lambda python script for processing.
import json
import urllib.parse
import boto3
import os
print('Loading function')
s3 = boto3.client('s3')
def lambda_handler(event, context):
# Get the object from the event and show its content type
bucket = os.environ['SOURCE_BUCKET_NAME']
key = urllib.parse.unquote_plus(event['Records'][0]['s3']['object']['key'], encoding='utf-8')
try:
video = s3.get_object(Bucket=bucket, Key=key)
print(video)
return event
except Exception as e:
print(e)
print('Error getting object {} from bucket {}. Make sure they exist and your bucket is in the same region as this function.'.format(key, bucket))
raise e
The 'video' object in-code is a dictionary, containing a 'Body' key with the value '<botocore.response.StreamingBody object at 0x7f0c0d4ec310'. I have tried a number of approaches to read this, including:
video = video['Body'].read()
which returns Bytes. When I try to read the bytes with open(...) or BytesIO, I get the error: "endswith first arg must be bytes or a tuple of bytes, not str".
I have also tried
video = video['Body'].read().decode()
which returns error: 'utf-8' codec can't decode byte 0x8e in position 29: invalid start byte.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论