开发者

How to save upload files to another server

I'm currently using django. And now I 开发者_运维知识库need to save a file uploaded by a user to another server which is not the one that serves the django application. The file will be saved to file system not the database. Could somebody tell me how to do this?


Default Django behavior is to save file on the filesystem, not the database itself).

You have several options how to do this, the simplest one is to have a filesystem exported from you "other" machine and mounted on the machine with the django application.

For the filesystem export you can use NFS, MogileFS or GlusterFS (which I'm using) or many more :). If you do not need real-time save&serve, simple rsync may be an option too.

Second option is to utilize existing django mechanisms StogareAPI. There are already available different storage backeds you can use and may be helpful for you (e.g. ftp).


This wont work out of the box, you need to have a mechanism(write some code) to queue the files that are uploaded through django application, then use a middleware(can be in python) to transfer files from queue to your file server. so flow is basically like this:

  1. Accept the uploaded file via django app.
  2. django app. writes the file info(its temporary path and name) to a queue
  3. A middleware app reads the next file in queue.
  4. The middleware app use some transfering protocol(sftp, scp, ftp, http etc...) to copy the file to file server.
  5. Middleware app deletes the file from where django app is hosted so django server dont have a copy of the file.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜