Permalink
Browse files

Add a util method for handling uploads from custom views

  • Loading branch information...
1 parent edec668 commit 158bc03bbdca7e22b4858d96df277d83e49aad0b @paltman paltman committed Nov 30, 2011
Showing with 23 additions and 0 deletions.
  1. +23 −0 chunked_uploads/utils.py
View
23 chunked_uploads/utils.py
@@ -0,0 +1,23 @@
+from chunked_uploads.models import Upload, Chunk
+
+
+def handle_upload(uploaded_file, who):
+ """
+ Expects to handle an individual file from request.FILES[name]
+
+ Returns an Upload object
+ """
+ u = Upload.objects.create(
+ user=who,
+ filename=uploaded_file.name,
+ filesize=uploaded_file.size
+ )
+ Chunk.objects.create(
+ upload=u,
+ chunk=uploaded_file,
+ chunk_size=uploaded_file.size
+ )
+ u.state = Upload.STATE_COMPLETE
+ u.save()
+ u.stitch_chunks()
+ return u

0 comments on commit 158bc03

Please sign in to comment.