varad
varad

Reputation: 8029

django multiple image uploading store uploaded image in a list

My form

<form method="get" action="" enctype="multipart/form-data">{% csrf_token %}

<input type="file" name="image" multiple />
<input type="submit" value="Submit" />

</form>

and here user can select and post multiple images.

When user posts multiple images at once I want to save them in a list so that I can iterate over them.

My view:

def MediaAddView(request):
# Here I want the list of all uploaded images
images = request.GET.get('image',None)
print images
if request.method == "POST":
    mod = Model()
    mod.thumb = one image from the list of image by iterating.
    mod.save()
    return HttpResponseRedirect("myUrl")
else:
    return render_to_response("anything.html", context_instance=RequestContext(request))

What I want is when user upload multiple image, all the images should be in a list.

Like so that I can iterate for image in images

Here when I did print images it prints only last image of the uploaded images. How can I store all the images into list ?

Upvotes: 1

Views: 655

Answers (1)

Daniel Roseman
Daniel Roseman

Reputation: 599600

You can't upload files with a GET request, only with a POST. And the files will then be found in request.FILES, so you can iterate over request.FILES.getlist('image') directly.

Upvotes: 2

Related Questions