异步文件上传到Amazon S3使用Django [英] Asynchronous File Upload to Amazon S3 with Django

查看:397
本文介绍了异步文件上传到Amazon S3使用Django的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用这个文件存储引擎的文件存储到亚马逊S3他们上载时:

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

<一个href="http://$c$c.welldev.org/django-storages/wiki/Home">http://$c$c.welldev.org/django-storages/wiki/Home

这需要相当长的时间上载,因为该文件必须首先从客户端至网络服务器,然后网络服务器到Amazon S3的响应被返回到客户端之前上载

It takes quite a long time to upload because the file must first be uploaded from client to web server, and then web server to Amazon S3 before a response is returned to the client.

我想使文件发送到S3异步的过程中,这样的反应可以更快返回给用户。什么是与该文件存储引擎做到这一点的最好方法是什么?

I would like to make the process of sending the file to S3 asynchronous, so the response can be returned to the user much faster. What is the best way to do this with the file storage engine?

谢谢你的建议!

推荐答案

我已经采取了另一种方法这个问题。

I've taken another approach to this problem.

我的机型有2文件字段,一个使用标准文件存储后端,另一个使用s3的文件存储后端。当用户上传一个文件时,它得到的localy存储。

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.

我有上传所有设置localY存储的文件,以S3和更新模型在我的应用程序管理命令。

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

所以,当一个请求进来的文件我检查,看看是否模型对象使用S3存储领域,如果是的话我送一个重定向到正确的URL在S3上,如果不是我发送重定向,以便nginx的能够服务于从磁盘文件。

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.

此管理命令可以ofcourse被任何事件一个cronjob或什么触发。

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

这篇关于异步文件上传到Amazon S3使用Django的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆