我正在尝试将文件转换为gzip文件,然后将它们上传到S3。当我签入S3时,文件就在那里,但是它们没有指定类型。如何指定内容类型?
for i in testList:
with contextlib.ExitStack() as stack:
source_file = stack.enter_context(open(i , mode="rb"))
destination_file = io.BytesIO()
destination_file_gz = stack.enter_context(gzip.GzipFile(fileobj=destination_file, mode='wb'))
while True:
chunk = source_file.read(1024)
if not chunk:
break
destination_file_gz.write(chunk)
destination_file_gz.close()
destination_file.seek(0)
bucket.upload_fileobj(destination_file, fileName, ContentType='application/gzip')如果我将ContentType作为参数添加到最后一行,我会得到一个错误:
"errorMessage": "bucket_upload_fileobj() got an unexpected keyword argument 'ContentType'",发布于 2021-10-20 23:16:12
使用
bucket.upload_fileobj(destination_file, fileName,ExtraArgs={'ContentType': "application/gzip"})https://stackoverflow.com/questions/69653457
复制相似问题