[Django]-Uploading multiple files in Django without using django.forms

6👍

Based on your file element form_file, the value in request.FILES['form_file'] should be a list of files. So you can do something like:

for upfile in request.FILES.getlist('form_file'):
    filename = upfile.name
    # instead of "filename" specify the full path and filename of your choice here
    fd = open(filename, 'w')
    fd.write(upfile['content'])
    fd.close()

Using chunks:

for upfile in request.FILES.getlist('form_file'):
    filename = upfile.name
    fd = open(filename, 'w+')  # or 'wb+' for binary file
    for chunk in upfile.chunks():
        fd.write(chunk)
    fd.close()
👤ars

Leave a comment