Uploading contents of Django FileField to a remote server
<p>In a Django project of mine, users upload video files. Initially, I was uploading them directly to Azure Blob Storage (equivalent to storing it on Amazon S3). I.e. in models.py I had:</p>

<pre><code>class Video(models.Model):
   video_file = models.FileField(upload_to=upload_path, storage=OverwriteStorage())
</code></pre>

<p>Where <code>OverwriteStorage</code> overrides <code>Storage</code> in <code>django.core.files.storage</code>, and essentially uploads the file onto Azure. </p>

<p>Now I need to upload this file to a separate Linux server (not the same one that serves my Django web application). In this separate server, I'll perform some operations on the video file (compression, format change), and then I'll upload it to Azure Storage like before.</p>

<p><strong>My question is:</strong> given my goal, how do I change the way I'm uploading the file in models.py? An illustrative example would be nice. I'm thinking I'll need to change <code>FileField.upload_to</code>, but all the examples I've seen indicate it's only to define a local filesystem path. Moreover, I don't want to let the user upload the content normally and then run a process to upload the file to another server. Doing it directly is my preference. Any ideas?</p>

<p>I've solved a similar issue with Amazon's S3, but the concept should be the same.</p>

<p>First, I use <code>django-storages</code>, and by default, upload my media files to S3 (<code>django-storages</code> also supports Azure). Then, my team set up an NFS share mount on our Django web servers from the destination server we occasional need to write user uploads to. Then we simply override <code>django-storages</code> by using "upload_to" to the local path that is a mount from the other server.</p>

<p>This answer has a quick example of how to set up an NFS share from one server on another: <a href="http://superuser.com/questions/300662/how-to-mount-a-folder-from-a-linux-machine-on-another-linux-machine">http://superuser.com/questions/300662/how-to-mount-a-folder-from-a-linux-machine-on-another-linux-machine</a></p>

<p>There are a few ways to skin the cat, but this one seemed easiest to our team. Good luck!</p>

python django file-upload django-models