将大文件添加到FileField时避免复制 [英] Avoid copying when adding a large file to FileField

查看:133
本文介绍了将大文件添加到FileField时避免复制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一些非常大的文件,这些文件不适合通过http上传,因此我的用户使用FTP上传文件,然后我的代码需要移到FileField.upload_to(通常在通过HTTP上传时结束).我的问题是,通常建议使用django.core.files.File的方法:

I'm dealing with some quite large files which are uncomfortable to upload via http, so my users upload files using FTP which my code then needs to move into FileField.upload_to (where they normally end up when uploaded via HTTP). My problem is, the commonly suggested method of using django.core.files.File:

from django.core.files import File

# filename is a FileField
file_obj = MyModel(filename=File(open('VIDEO_TS.tar', 'rb')))

导致复制数据,这是我需要避免的.在确保调用upload_to的同时,有什么方法可以将现有文件添加到FileField中?

leads to copying the data, which i need to avoid. Is there any way to add the already existing file to a FileField while making sure upload_to is called?

推荐答案

我会说,最简单的方法是编写自己的字段或存储.

I'd say that easiest way would be writing your own field or storage.

这篇关于将大文件添加到FileField时避免复制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆