thoslin
thoslin

Reputation: 7019

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?

Upvotes: 2

Views: 5833

Answers (2)

Jerzyk
Jerzyk

Reputation: 3752

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).

Upvotes: 3

Numenor
Numenor

Reputation: 1706

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.

Upvotes: 0

Related Questions