Uploaded File Array

89 views
Skip to first unread message

BarakatX2

unread,
Jun 29, 2009, 11:05:27 AM6/29/09
to Django users
I have a form that allows a dynamic number of files to be uploaded. On
the Django side, if I print the request.FILES it is described as:

<MultiValueDict: {u'rqFiles': [<InMemoryUploadedFile: add.png (image/
png)>, <InMemoryUploadedFile: del.png (image/png)>,
<InMemoryUploadedFile: up.png (image/png)>]}>

But when I try to access the files like this:

for f in files['rqFiles']:

Then f is a string with some ascii characters including the file
extension. Shouldn't it be an InMemoryUploadedFile? How should I be
accessing files['rqFiles']? Thanks for any help.

Rajesh D

unread,
Jun 29, 2009, 11:48:43 AM6/29/09
to Django users


On Jun 29, 11:05 am, BarakatX2 <baraka...@gmail.com> wrote:
> I have a form that allows a dynamic number of files to be uploaded. On
> the Django side, if I print the request.FILES it is described as:
>
> <MultiValueDict: {u'rqFiles': [<InMemoryUploadedFile: add.png (image/
> png)>, <InMemoryUploadedFile: del.png (image/png)>,
> <InMemoryUploadedFile: up.png (image/png)>]}>
>
> But when I try to access the files like this:
>
> for f in files['rqFiles']:
>
> Then f is a string with some ascii characters including the file
> extension. Shouldn't it be an InMemoryUploadedFile?

Yes. How are you checking that it is not? If you just print "f", you
will see the name of the file but its type would be correct.

> How should I be
> accessing files['rqFiles']?

Go through this doc: http://docs.djangoproject.com/en/dev/topics/http/file-uploads/#handling-uploaded-files

On each of your files, you could use the f.chunks() method described
in the example in the above doc.

-RD

BarakatX2

unread,
Jun 29, 2009, 12:03:35 PM6/29/09
to Django users
When I do:

print type(f)

It outputs:

<type 'str'>

Also when I try to get the filename using the name property of
UploadedFile, it says:

'str' object has no attribute 'name'

When I just print f it shows:

ëPNG

On Jun 29, 10:48 am, Rajesh D <rajesh.dha...@gmail.com> wrote:
> On Jun 29, 11:05 am, BarakatX2 <baraka...@gmail.com> wrote:
>
> > I have a form that allows a dynamic number of files to be uploaded. On
> > the Django side, if I print the request.FILES it is described as:
>
> > <MultiValueDict: {u'rqFiles': [<InMemoryUploadedFile: add.png (image/
> > png)>, <InMemoryUploadedFile: del.png (image/png)>,
> > <InMemoryUploadedFile: up.png (image/png)>]}>
>
> > But when I try to access the files like this:
>
> > for f in files['rqFiles']:
>
> > Then f is a string with some ascii characters including the file
> > extension. Shouldn't it be an InMemoryUploadedFile?
>
> Yes. How are you checking that it is not? If you just print "f", you
> will see the name of the file but its type would be correct.
>
> > How should I be
> > accessing files['rqFiles']?
>
> Go through this doc:http://docs.djangoproject.com/en/dev/topics/http/file-uploads/#handli...

Rajesh Dhawan

unread,
Jun 29, 2009, 12:20:44 PM6/29/09
to Django users


BarakatX2 wrote:
> When I do:
>
> print type(f)
>
> It outputs:
>
> <type 'str'>
>
> Also when I try to get the filename using the name property of
> UploadedFile, it says:
>
> 'str' object has no attribute 'name'
>
> When I just print f it shows:
>
> ëPNG

Try something like this code:

for fname, fvalue in request.FILES.iteritems():
print fname # This is the submitted file name
print type(fvalue) # This is the file object

-RD
Reply all
Reply to author
Forward
0 new messages