我在Ubuntu 16.04 LTS中使用Python 2.7.12.我正在学习如何使用以下链接中的boto3:https://boto3.readthedocs.io/en/latest/guide/quickstart.html#using-boto-3 .我怀疑的是何时使用资源,客户端或会话以及它们各自的功能.
我试图使用Boto3将文件上传到s3并将上传的文件公开并将其作为网址返回.
class UtilResource(BaseZMPResource):
class Meta(BaseZMPResource.Meta):
queryset = Configuration.objects.none()
resource_name = 'util_resource'
allowed_methods = ['get']
def post_list(self, request, **kwargs):
fileToUpload = request.FILES
# write code to upload to amazone s3
# see: https://boto3.readthedocs.org/en/latest/reference/services/s3.html
self.session = Session(aws_access_key_id=settings.AWS_KEY_ID,
aws_secret_access_key=settings.AWS_ACCESS_KEY,
region_name=settings.AWS_REGION)
client = self.session.client('s3')
client.upload_file('zango-static','fileToUpload')
url = "some/test/url"
return self.create_response(request, {
'url': url // return's public url of uploaded file
})
Run Code Online (Sandbox Code Playgroud)
我搜索了整个文档,我找不到任何链接,描述如何做到这一点,有人可以解释或提供任何资源,我可以找到灵魂?