[英]POST url to S3 directly
Given a url of a downloadable file, such as: 给出可下载文件的网址,例如:
http://zannee-docs.s3.amazonaws.com/rockefeller-summary.pdf
Is there a way to POST / PUT this directly to S3? 有没有一种方法可以直接将此POST / PUT发送到S3? Or is it necessary that I do:
还是我有必要这样做:
# download the file
requests.get(url, stream=True)
# save the file locally
# upload the local file to S3
s3.upload_file()
If there is a way to upload it directly to S3 (without having to download it and re-upload it to S3), how would I do this? 如果有一种方法可以直接将其上传到S3(而不必下载并将其重新上传到S3),我该怎么做?
Yes, but only if the source URL is also hosted in S3, and your S3 key can access it. 是的,但只有当源URL也托管在S3和S3的按键可以访问它。 (The documentation doesn't say this explicitly, but I think the source object needs to be stored in the same region as well.)
(文档中没有明确说明这一点,但我认为源对象也需要存储在同一区域中。)
http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectCOPY.html http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectCOPY.html
Since you're using boto, the specific API you'll want is boto.s3.key.Key.copy()
. 由于您使用的是boto,因此需要的特定API是
boto.s3.key.Key.copy()
。
It is possible to use pre-signed URLs to PUT objects directly to S3. 可以使用预签名的URL将对象直接放置到S3。 I don't believe you could get it work with POST because POST has to encode the body of the request but perhaps there is a way to do that, too.
我不认为您可以将它与POST一起使用,因为POST必须对请求的主体进行编码,但是也许也可以做到这一点。 This SO thread should be useful:
这个SO线程应该有用:
How to generate a temporary url to upload file to Amazon S3 with boto library? 如何使用Boto库生成临时URL以将文件上传到Amazon S3?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.