我想用django同时使用几个硬盘来存储我的文件。我的目标是将大文件存储在服务器上并在本地网络上共享。
我想知道如何继续将我的文件存储在几个磁盘中以及当第一个磁盘已满时django会如何反应。想法是填充第一个,然后切换到第二个。显然,如果我们删除第一个文件,我们就会重复使用它。
答案 0 :(得分:1)
我不认为django可以管理这样的需求"开箱即用"但你可以通过制作自己的" UploadHandler"
来实现这样的功能您可以从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
在settings.py中,定义:
FILE_UPLOAD_HANDLERS = [
'path.to.MyUploadHandler
]
请参阅https://docs.djangoproject.com/en/2.0/ref/files/uploads/#writing-custom-upload-handlers