【发布时间】:2017-07-21 10:36:43
【问题描述】:
如何将文件从我的 AppEngine 应用程序上传到 AWS S3?用户提交文件上传表单并从 AppEngine 应用程序,使用 python 我必须将文件上传到 S3。
class FileUpload(webapp2.RequestHandler):
def post(self):
file_data = self.request.POST['file']
要将文件对象上传到 S3,我们必须使用open 方法。 Boto Docuement
with open('filename', 'rb') as data:
s3.upload_fileobj(data, 'mybucket', 'mykey')
那么在这里我如何使用open 方法访问file_data 对象?
【问题讨论】:
-
为什么不上传到谷歌自己的Cloud Storage?
-
由于特定的架构设计,我们不得不使用S3而不是GCS。
-
根据boto3.readthedocs.io/en/latest/reference/services/…,您只需要确保file_data 是字节类型。然后你可以直接使用 s3.upload_fileobj(file_data, 'mybucket', 'mykey') 来上传你的数据。
-
@kakashi 但是如何替换
with open?
标签: python google-app-engine amazon-s3 boto3 webapp2