Answer the question
In order to leave comments, you need to log in
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"
})
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question