M
M
Maxim2016-09-09 12:29:55
Django
Maxim, 2016-09-09 12:29:55

How to multi-upload a file?

@csrf_exempt
def upload_file(request):
    if request.method == 'POST':
        try:
            file = request.FILES['data']
            destination = open(upload_dir + file.name, 'wb+')
            for chunk in file.chunks():
                destination.write(chunk)
                destination.close()
            return JSONResponse({
                'success': True,
                'message': 'File upload successful',
                'path': upload_dir+file.name
            })
        except Exception as e:
            return JSONResponse({
                'success': False,
                'message': "fail to upload file"
            })

this way I get the file, but how to check how many files have arrived and then save them all?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question