multiple files upload using same input name in django

前端 未结 4 921
北海茫月
北海茫月 2020-11-30 02:45

i m having trouble in uploading multiple files with same input name:





        
4条回答
  •  半阙折子戏
    2020-11-30 03:03

    Given your url points to envia you could manage multiple files like this:

    #!/usr/bin/env python
    # -*- coding: UTF-8 -*-
    from django.http import HttpResponseRedirect
    
    def envia(request):
        for f in request.FILES.getlist('file'):
            handle_uploaded_file(f)
        return HttpResponseRedirect('/bulk/')
    
    def handle_uploaded_file(f):
        destination = open('/tmp/upload/%s'%f.name, 'wb+')
        for chunk in f.chunks():
            destination.write(chunk)
        destination.close()
    

提交回复
热议问题