David542
David542

Reputation: 110163

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? 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?

Upvotes: 0

Views: 1017

Answers (2)

garnaat
garnaat

Reputation: 45856

It is possible to use pre-signed URLs to PUT objects directly to 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. This SO thread should be useful:

How to generate a temporary url to upload file to Amazon S3 with boto library?

Upvotes: 0

user149341
user149341

Reputation:

Yes, but only if the source URL is also hosted in S3, and your S3 key can access it. (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

Since you're using boto, the specific API you'll want is boto.s3.key.Key.copy().

Upvotes: 3

Related Questions