How to save upload files to another server

后端 未结 2 1689
抹茶落季
抹茶落季 2021-01-22 09:10

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

相关标签:
2条回答
  • 2021-01-22 09:48

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

    0 讨论(0)
  • 2021-01-22 10:02

    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 讨论(0)
提交回复
热议问题