我正在尝试boto3
在我的 django 项目中使用将文件上传到 Amazon S3。凭证定义在settings.py
:
AWS_ACCESS_KEY = xxxxxxxx
AWS_SECRET_KEY = xxxxxxxx
S3_BUCKET = xxxxxxx
在views.py
:
import boto3
s3 = boto3.client('s3')
path = os.path.dirname(os.path.realpath(__file__))
s3.upload_file(path+'/myphoto.png', S3_BUCKET, 'myphoto.png')
系统抱怨Unable to locate credentials
。我有两个问题:
(a) 看来我应该创建一个凭证文件~/.aws/credentials
。但是在 django 项目中,我必须把它放在哪里?
(b) s3 方法upload_file
将文件路径/名称作为其第一个参数。是否可以提供由表单输入元素获得的文件流<input type="file" name="fileToUpload">
?