我正在嘗試將檔案轉換為 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'",
uj5u.com熱心網友回復:
用
bucket.upload_fileobj(destination_file, fileName,ExtraArgs={'ContentType': "application/gzip"})
請參閱使用 Boto3 的 S3 中的 AWS 內容型別設定
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/329546.html
標籤:Python 亚马逊网络服务 亚马逊-s3 boto3 博托
