當我嘗試使用 python 和 boto3 將檔案上傳到我的 ASW s3 時它作業正常并且我能夠成功地將它上傳到 aws s3 但是當我嘗試上傳一個檔案夾時我得到了
getting PermissionError: [Errno 13]
我的代碼是
def upload_to_aws(local_file, bucket, s3_file):
s3 = boto3.client('s3', aws_access_key_id=ACCESS_KEY,
aws_secret_access_key=SECRET_KEY)
try:
s3.upload_file(local_file, bucket, s3_file)
print("Upload Successful")
return True
except FileNotFoundError:
print("The file was not found")
return False
except NoCredentialsError:
print("Credentials not available")
return False
uj5u.com熱心網友回復:
upload_file僅用于上傳檔案,而不是檔案夾。您必須遍歷檔案夾中的所有檔案,并對每個檔案執行upload_file操作。
uj5u.com熱心網友回復:
@Marcin 是對的。
了解 s3 存盤桶的結構也很重要。因為s3是一個物件存盤,它實際上沒有檔案夾結構。您在存盤桶中創建的檔案夾只是按檔案名(如/**folder**/myfile.pdf. 這樣做是為了讓我們可以更輕松地與物件互動。但 S3 不是檔案存盤。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/403116.html
標籤:
上一篇:洗掉S3過時的生命周期規則
