0

I have an endpoint where I want to collect the response data and dump it into a file on S3 like this - https://stackoverflow.com/a/18731115/4824482

This is how I was trying to do it -

file_obj = open('/some/path/log.csv', 'w+')
file_obj.write(request.POST['data'])

and then passing file_obj to the S3 related code as in the above link.

The problem is that I don't have permissions to create a file on the server. Is there any way I can create a file object just in memory and then pass it to the S3 code?

0

2 Answers 2

2

Probably that's duplicate question of How to upload a file to S3 without creating a temporary local file. You would find best suggestion by checking out answers to that question.

Shortly the answer is code below:

from boto.s3.key import Key
k = Key(bucket)
k.key = 'yourkey'
k.set_contents_from_string(request.POST['data'])
Sign up to request clarification or add additional context in comments.

Comments

2

Try tempfile https://docs.python.org/2/library/tempfile.html

f = tempfile.TemporaryFile()
f.write(request.POST['data'])

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.