Opened 10 years ago

Closed 10 years ago

Last modified 9 years ago

#9396 closed (invalid)

FILE_UPLOAD_TEMP_DIR ignored on Windows?

Reported by: spkane Owned by: nobody
Component: Database layer (models, ORM) Version: 1.0
Severity: Keywords: FILE_UPLOAD_TEMP_DIR, SuspiciousActivity, Windows
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


When running Django 1.0 on Windows XP, I am getting an error when uploaded a headshot (image), while adding an author from the Chapter 6 tutorial in the Django Apress book. The error is related to "SuspiciousActivity", however my FILE_UPLOAD_TEMP_DIR directory is set to 'c:\djcode\mysite\temp' which should be safe. The issue, based on the error message, however seems to be that it is actually trying to save the image into /tmp, which of course causes a problem on Windows. I was able to get this working for myself by patching django\db\models\fields\

I am a pretty new Python programmer and I realize that this patch is a hack, since I am forcing something to happen here and possibly over ridding a legitimate value. I tried to change the initial init from upload_to= to upload_to=settings.FILE_UPLOAD_TEMP_DIR. However that didn't work, so it seems that the class is getting initialized with a value, but it is the wrong value, and I could not trace the code back any further. This patch works for me, but it would be nice to have a proper solution in the future.

Attachments (1)

django.dbmodels.fields.files.patch (440 bytes) - added by spkane 10 years ago.
Patch (Hack) - Needs much better implementation

Download all attachments as: .zip

Change History (4)

Changed 10 years ago by spkane

Patch (Hack) - Needs much better implementation

comment:1 Changed 10 years ago by Karen Tracey

Resolution: invalid
Status: newclosed

There's not enough information here to diagnose what is going wrong. I'm reasonably certain that FILE_UPLOAD_TEMP_DIR is not ignored on Windows (I believe I've used it in the past, and it has worked properly), so I suspect user error. Please post to django-users and include:

1 - The actual title of the book you are using. There is more than one Django book published by Apress, and the one that is available for reading online has no mention of uploading files in chapter 6, so you must be using a different one.

2 - Some description of what you are doing and at least bits of the code involved. Not everyone who might be able to help has a copy of every Django book out there, so unless you describe what's being covered in chapter 6 you'll be limiting help to those people who have that book.

3 - The full error message you are getting, including traceback if there is one. Saying its "related to SuspiciousActivitty" is not enough information for people to go on.

If after discussion on django-users it becomes clear that there is actually an error in the Django code, then open a ticket.

One thing I will mention is that the problem may be related to how you have specified your FILE_UPLOAD_TEMP_DIR. In Python backslashes in string literals are escape characters, so setting FILE_UPLOAD_TEMP_DIR = 'c:\djcode\mysite\temp' won't work as expected. You need to either use forward slashes, specify the setting as a raw string (i.e. r'c:\djcode\mysite\temp'), or double the backslahses.

Also for future reference when attaching patch files please create the patch from the root of the django tree, so that the full path name of the file is clear.

comment:2 in reply to:  1 Changed 10 years ago by spkane

While responding to this I figured out the issue. I would say that it is a bug in the book (The Definitive Guide to Django). Or at least something that should have included a caveat for folks not on Unix systems. In the author model the book has you write, it defined the field AND the upload location in the code:

headshot = models.ImageField(upload_to='/tmp')

which was not at all apparent multiple chapters later when I started to use that field. I'm not even sure it would work as is, since I believe that Django will trigger an "Suspicous Activity" warning because this is outside of the Django project hierarchy.

However, the general problem is fixed. Thank you for the detailed response.


comment:3 Changed 9 years ago by (none)

milestone: post-1.0

Milestone post-1.0 deleted

Note: See TracTickets for help on using tickets.
Back to Top