3

I have successfully stored a Word document to S3 using Django-storages.

class Document(TitleSlugDescriptionModel, TimeStampedModel):
    document = models.FileField(upload_to=user_directory_path)

Now in celery task, I need to download this file again for further processing in the worker.

Do I need to read the file from URL and then create the local copy explicitly or is there any way to create local copy using Django-storages?

1 Answer 1

0

You can read the file directly in Django using the read method as in document.read() this will output binary which you can save to a file using

f=open(filename, 'wb')
f.write(document.read())
f.close

You can also generate URLs to the file on S3 as well. More info on both in the docs: https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html

Sign up to request clarification or add additional context in comments.

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.