On Fri, 2009-07-31 at 11:42 -0400, Faheem Mitha wrote:
> 
> Hi everybody,
> 
> I upgraded from somewhere around Django 1.0 to 1.0.2, and some things 
> broke and had to be changed. In the following, f is an object of class 
> 'django.core.files.uploadedfile.TemporaryUploadedFile'. I need to
> 
> 1) Get the contents of the file corresponding to f. I had to change 
> f['content'] to f._file.read()
> 
> From the docs (specifically, 'core/files/uploadedfile.py') it looks like 
> f.read() might be the right thing?

The correct way to access uploaded file data is documented here:
http://docs.djangoproject.com/en/dev/topics/http/file-uploads/#handling-uploaded-files

That is the public API, and you are correct in thinking that read() is
the method you're after here.

> 
> 2) Get the filename of the file corresponding to f. I had to change 
> f['filename'] to f._name.

This is also documented in the above reference. Use the "name" attribute
on the UploadedFile isntance.

> 
> 3) Get the sessionid. I had to change request.COOKIES['sessionid'] to 
> request.COOKIES[settings.SESSION_COOKIE_NAME]

The default value of settings.SESSION_COOKIE_NAME has always (and
remains) "sessionid". However, it's a little more portable to use the
latter form (request.COOKIES[settings.SESSION_COOKIE_NAME) in your
applications, since then they are usable no matter what the setting
happens to be. A Django application writer is not necessarily in control
of the settings that will be used when the application is installed.


> 
> It is presumably better to use a stable API rather than less stable 
> internals,

It is *always* better. :-)

Regards,
Malcolm


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to