강미란
강미란

Reputation: 13

How can I used multiple file I receive in "request.FILES"?

If "request.FILES" have multiple file, how can i use it? I want to get data from input tag(type="file" name="file" multiple) and upload this data.

i can use just one image. But not multiple. =(


def post(self, request, *args, **kwargs):
    print(request.FILES) 
    #<MultiValueDict: {u'file': [<InMemoryUploadedFile: emo1.png (image/png)>, <InMemoryUploadedFile: emo2.png (image/png)>]}>
    if 'file' in request.FILES:
        print(request.FILES['file'])
        #emo2.png
        #there is only one image left....

for file in request.FILES['file']:
    #i want write upload file code

Upvotes: 1

Views: 1307

Answers (1)

Dipen Dadhaniya
Dipen Dadhaniya

Reputation: 4630

Try:

files = request.FILES.getlist('file')
for file in files:
    pass

Read more about it in Django's official documentation.

Upvotes: 2

Related Questions