Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

request.FILES.getlist('file') is empty

Tags:

python

django

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>
like image 932
user3720855 Avatar asked Jun 09 '14 01:06

user3720855


2 Answers

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']

like image 198
Llanilek Avatar answered Oct 31 '22 08:10

Llanilek


Instead of doing this: descriptions = request.POST.getlist ('descriptions')

Try it like this: descriptions = request.FILES.getlist ('descriptions []')

In my case it worked.

like image 26
user15888350 Avatar answered Oct 31 '22 10:10

user15888350