I am sending few files to the request with dropzone.js
but the request.FILES.getlist()
seems to be completely empty. Any possible reasons as to why?
--sorry that was just a typo in my question. it is FILES
in my code.
def upload(request):
user = request.user
theAccount = user.us_er.account
if request.method == "POST":
form = uploadForm(request.POST)
if form.is_valid():
descriptions = request.POST.getlist('descriptions')
count = 0
for f in request.FILES.getlist('file'):
theAccount.file_set.create(docFile = f, description = descriptions[count], dateAdded = timezone.now(), creator = user.username)
count = count + 1
return HttpResponseRedirect('/home/')
else:
return HttpResponse("form is not valid")
else:
return HttpResponse('wasnt a post')
this is my template containing with the dropzone.
<form method="POST" style="border: 2px solid green;" action= "/upload/" enctype="multipart/form-data" class="dropzone">
{% csrf_token %}
<div class="dropzone-previews"></div>
<button value=" submit" class="btn btn-success" type="submit" id="submit">Press to upload!</button>
</form>
I know this is an old question, but for the sake of people landing here through google.
Dropzone.js uses ajax to upload files in a queue, so your endpoint should process the upload as a singular file not multiple.
You can access the file via request.FILES['file']
Instead of doing this: descriptions = request.POST.getlist ('descriptions')
Try it like this: descriptions = request.FILES.getlist ('descriptions []')
In my case it worked.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With