我不知道我是否理解你想包含在管理區域中。您是否正在尋找一種使用HTTP以外的傳輸協議自動執行文件上傳過程的方法?
如果是這樣,您可以使用基本CharField(或可能是URLField)創建模型,然後在保存對象時執行rsync或scp複製。例如:
from django.db import models
class File(models.Model):
path = models.CharField()
def save(self):
import os
# WARNING! The path given by the user should be sanitized; this is
# example code only. This is a security vulnerability.
# Attempt to rsync the target file from a remote machine
exit_code = os.system("rsync %s /incoming/files/path/" % self.path)
# Make sure it worked before saving
if exit_code == 0:
super(File, self).save() # Call the "real" save() method
else:
# Raise exception
這是一個非常粗略的例子,但它應該可以幫助您計算出某些東西。您需要確保您的例程安全(格式不正確的路徑可能允許用戶運行任何他們想要的內容)。此外,這可能會阻止Django保存例程,同時複製文件,因此您應該查看在單獨的進程中運行您的首選命令。
祝你好運!
好奇,想看看是什麼迴應是,我需要很快處理這個相同的問題 - 大量文件從100-200mb,通過管理員上傳到S3。 – 2009-08-11 23:05:42
我用FilePathField做了一個表單,它工作正常,但需要重新加載Web服務器才能看到新文件:/ - 仍在尋找替代方法! – user130924 2009-08-14 11:10:50