加密InMemoryUploadfile并将加密的文件保存在磁盘上

时间:2018-11-28 00:03:30

标签: python django python-2.7

我搜索了用于用户上传文件的加密解决方案。我找到了所有教程或解决方案,有关在磁盘上打开现有文件进行加密并将其保存到磁盘的地方。我正在尝试加密用户上传的文件,而不保存原始文件,而是直接保存加密的文件。 马上 用户上传>保存到磁盘>打开文件>加密>保存加密的文件>删除原始文件,我现在正在执行此操作。

def upload_file:
for file_name, each_file in request.FILES.items():
incoming_file = each_file
save_path = "abc/%s/%s" % (request.user, user_id)
abs_filename = os.path.join(settings.PATH, save_path)
normalize_path = os.path.normpath(abs_filename)
if not os.path.exists(abs_filename):
os.makedirs(abs_filename)
path = normalize_path
if os.path.exists(os.path.normpath(abs_filename)):
path = normalize_path
fs = FileSystemStorage(location=path)  # (location='/media/')
doc_data = incoming_file.read()
filename = incoming_file.name
size_a = incoming_file.size
content_type = incoming_file.content_type
filename = fs.save(incoming_file.name.replace(" ","_"), incoming_file)
Document(document_type=content_type,file_name=filename,document_path="media/abc/" + filename,file_size=size_a,contract_id=data,user_id=user_id,original_path=path).save()
return

0 个答案:

没有答案