English 中文(简体)
Django在哪里储存临时上传文件?
原标题:Where does django store temporary upload files?

我有一个Django/ uwsgi/ nginx 堆叠在 CentOS 上运行。 当将大文件上传到 Django ( 1GB+) 时, 我期望它会在 < code>/ tmp 中创建一个临时文件, 并且随着上传的进展, 我应该能看到文件的成长。 但是, < code> ls -lah/ tmp 没有显示正在创建或改变大小的任何新文件 。 我甚至在我的 < code> 设置中指定了 。 py < / code > 明确显示 < code> FILE_ UPOLAD_ TEMP_ DIR =/ tmp < /code > 但仍然没有显示。

我很感激你帮忙追踪临时文件的存放地点 我需要这个来确定是否有大型上传在进行中

问题回答

它们储存在您的系统临时目录中。 从https://docs.djangoproject.com/en/dev/topics/http/file-uploads/?from=olddocs :

<% 1> 存储上载数据的地方

在保存上传文件之前,数据需要保存在某个地方。

By default, if an uploaded file is smaller than 2.5 megabytes, Django will hold the entire contents of the upload in memory. This means that saving the file involves only a read from memory and a write to disk and thus is very fast.

However, if an uploaded file is too large, Django will write the uploaded file to a temporary file stored in your system s temporary directory. On a Unix-like platform this means you can expect Django to generate a file called something like /tmp/tmpzfp6I6.upload. If an upload is large enough, you can watch this file grow in size as Django streams the data onto disk.

These specifics -- 2.5 megabytes; /tmp; etc. -- are simply "reasonable defaults". Read on for details on how you can customize or completely replace upload behavior.

此外,这只有在一定大小(默认为2.5MB)之后才会发生。

FILE_UPLOAD_MAX_MEMORY_SIZE The maximum size, in bytes, for files that will be uploaded into memory. Files larger than FILE_UPLOAD_MAX_MEMORY_SIZE will be streamed to disk.

默认值为 2.5 兆字节。

我刚用决哥的1.4.1 追踪到这个 在我的OS X系统上

在django/core/files/ uploadfile.py 中,使用 django.core.files.temp 创建临时文件, 作为临时文件导入

from django.core.files import temp as tempfile 

这只返回 Python s 标准临时文件。 NamedTemporaryFile, 除非它在 Windows 上运行 。

查看临时工的位置, 您可以在 shell 执行此命令 :

python -c "import tempfile; print tempfile.gettempdir()"

在我现在的系统上 它的输出 /var/folders/9v/npjlh_kn7s9fv5p4dwh1spdr00gn/T, 我在那里找到了我临时上传的文件。





相关问题
How to get two random records with Django

How do I get two distinct random records using Django? I ve seen questions about how to get one but I need to get two random records and they must differ.

Moving (very old) Zope/Plone Site to Django

I am ask to move data from a (now offline) site driven by Plone to a new Django site. These are the version informations I have: Zope Version (unreleased version, python 2.1.3 ) Python Version 2.1....

Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

Flexible pagination in Django

I d like to implement pagination such that I can allow the user to choose the number of records per page such as 10, 25, 50 etc. How should I go about this? Is there an app I can add onto my project ...

is it convenient to urlencode all next parameters? - django

While writing code, it is pretty common to request a page with an appended "next" query string argument. For instance, in the following template code next points back to the page the user is on: &...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

热门标签