Wednesday, January 23, 2013

Re: Upload multiple files using Ajax

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


On Wed, Jan 23, 2013 at 1:22 AM, Mengu <whalberg@gmail.com> wrote:
> 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/
>
> On Jan 22, 6:05 pm, Andre Lopes <lopes80an...@gmail.com> wrote:
>> 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é.
>
> --
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
>

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

No comments:

Post a Comment