Iggdrazil
Iggdrazil

Reputation: 55

Store file on several hard drives with Django

I'd like to use several hard drives at the same time with django to store my files. My goal is to store big files on a server and share it on a local network.

I would like to know how to proceed in order to store my files in several disk and how django would react when the first disk is full. The idea would be to fill the first one and then switch to the second one. Obviously, if we remove a file in the first one, we re-use it.

Upvotes: 0

Views: 362

Answers (1)

luc
luc

Reputation: 43096

I don't think that django can manage such need "out-of-the-box" but you can probably implement such feature by making your own "UploadHandler"

You can inherit a class from FileUploadHandler

 from django.core.files.uploadhandler import FileUploadHandler
 class MyUploadHandler(FileUploadHandler):

      def receive_data_chunk(self, raw_data, start):
             """ doc says:
             Receives a “chunk” of data from the file upload.
             raw_data is a byte string containing the uploaded data.
             start is the position in the file where this raw_data chunk begins.
             """
             # Here get a temporary copy of file content

      def file_complete(self, file_size):
          """Called when a file has finished uploading."""
          # Here manage the copy on one of your hard disks

In settings.py, define:

FILE_UPLOAD_HANDLERS = [
    'path.to.MyUploadHandler
]

See https://docs.djangoproject.com/en/2.0/ref/files/uploads/#writing-custom-upload-handlers

Upvotes: 1

Related Questions