views:

218

answers:

5

Hi

I want to receive multi file post from image uploader.(i use this) Most examples show how to receive one image from post.

I tried many ways but never got the results. For example

self.request.POST['Filename']

gives only first filename.

What to do when there are multiple files/images in post?

The reason for this is to resize before upload images, that are too big for google app engine to upload.

EDIT:

self.request.POST.multi.__dict__

shows

{'_items':
[('Filename', 'camila1.jpg'),
('Filedata[]', FieldStorage('Filedata[]', 'camila1.jpg')),
('Upload', 'Submit Query\r\n--negpwjpcenudkacqrxpleuuubfqqftwm----negpwjpcenudkacqrxpleuuubfqqftwm\r\nContent-Disposition: form-data; name="Filename"\r\n\r\nbornToBeWild1.jpg'),
('Filedata[]', FieldStorage('Filedata[]', 'bornToBeWild1.jpg')),
('Upload', 'Submit Query')]}
+1  A: 

Are you using the Django libraries available to you? If so, check this out.

Andrew Sledge
I'm using just default frame work.
Chris
A: 

I have no idea how that multi uploader works, I have made one in the past however and I just added a number on the end of input field name, then hide it. Then add a new file input field to add another file. The reason for this is that they don't let you play around with input file fields to much because you could make it upload files they didn't want you uploading.

Using my conventions, in your example the 2 files in your example would be "Filename0" and "Filename1". You could also use firebug to see what it renaming the input file fields to.

Edit: I had a look, and it's using flash. So i have no idea how it works.

UK-AL
A: 

Call self.request.POST.getall('Filename') to get a list of FieldStorage objects; each one contains one file. You can access the file data with .value, the name with .name, and the mimetype with .type.

Nick Johnson
+2  A: 

Your flash uploader is designed to work with PHP and sends multiple Filedata[] fields (php interprets this as an array for easy access)

So you need to iterate and get them all:

def post(self):
  for file_data in self.request.POST.getall('Filedata[]'):
     logging.info(file_data.filename)

data should be file_data.value

Thank you very much:)
Chris
A: 

here's an app and one more allowing multiple file http posts from disposable code all google appengine default django framework I hope help. My helperfunction is

        def create_image(number, self, file):
          images.resize...

loop calling it:

create_image('file', self, self.request.POST.get('file').file.read(), myModel)
LarsOn