Asynchronous File Upload to Amazon S3 with Django

后端 未结 7 1185
轻奢々
轻奢々 2021-01-30 04:18

I am using this file storage engine to store files to Amazon S3 when they are uploaded:

http://code.welldev.org/django-storages/wiki/Home

It takes quite a long t

7条回答
  •  滥情空心
    2021-01-30 04:40

    I've taken another approach to this problem.

    My models have 2 file fields, one uses the standard file storage backend and the other one uses the s3 file storage backend. When the user uploads a file it get's stored localy.

    I have a management command in my application that uploads all the localy stored files to s3 and updates the models.

    So when a request comes for the file I check to see if the model object uses the s3 storage field, if so I send a redirect to the correct url on s3, if not I send a redirect so that nginx can serve the file from disk.

    This management command can ofcourse be triggered by any event a cronjob or whatever.

提交回复
热议问题