Upload multiple files using Ajax

442 views
Skip to first unread message

Andre Lopes

unread,
Jan 22, 2013, 4:05:43 PM1/22/13
to django...@googlegroups.com
Hi,

I need to develop a form to upload multiple files.

I was thinking in using an Ajax uploader. I have google some options
but there are to many and I don't know which one to choose.

Any recommendations about this subject?


Best Regards,
André.

Mengu

unread,
Jan 22, 2013, 7:52:26 PM1/22/13
to Django users
i used jquery.form plugin back in the day. it worked great but it had
issues with large files.

check out http://malsup.com/jquery/form/progress3.html and
http://malsup.com/jquery/form/

Pankaj Singh

unread,
Jan 23, 2013, 10:18:01 AM1/23/13
to django...@googlegroups.com
You can use https://github.com/blueimp/jQuery-File-Upload.

You can use a view function similar to following. Here I have 3 models
- Project, Album and Flat

A Project can have multiple albums.
An Album can have multiple Flats
A Flat has an ImageField, caption as TextField and a ForeignKey to Album.

def upload_flat(request, project_slug, album_pk):
project = get_object_or_404(Project, slug=project_slug)
album = get_object_or_404(Album, pk=album_pk)
if request.method == 'GET':
flats = album.flat_set.all()
return render(request, "upload.html", {"project": project,
"album": album, "flats": flats})

if request.method == "POST":
form = FlatForm(request.POST, request.FILES)
if form.is_valid():
flat = form.save(commit=False)
flat.user = request.user
flat.album = album
flat.save()

data = {
"files":
[{
"url": flat.image.url,
"thumbnail_url": flat.thumbnail.url,
"name": flat.image.name,
"type": "image/jpeg",
"size": flat.image.size,
"delete_url": reverse("delete_flat", args=[flat.pk]),
"delete_type": "DELETE",
"description": flat.description
}]
}
return HttpResponse(simplejson.dumps(data))
return render(request, "upload.html", {})

--
Pankaj Singh
http://about.me/psjinx
> --
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To post to this group, send email to django...@googlegroups.com.
> To unsubscribe from this group, send email to django-users...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
>

Barry Morrison

unread,
Jan 23, 2013, 7:57:40 PM1/23/13
to django...@googlegroups.com
I created this https://github.com/esacteksab/django-jquery-file-upload which is just jQuery-File-Upload ported to Django. It was a fork of someone elses' project that addressed my needs (support for models)
Reply all
Reply to author
Forward
0 new messages