4

The question is stated above. While there are many tutorials about file upload using django rest framework. None mentioned about the resumable version of it. And I need to implement it for a project. Can someone point me to some resources or give a sample code? Help is greatly appreciated.

UPDATE

This is what I have gotten so far.

views.py

class FileUploadView(views.APIView):
    parser_classes = (FormParser, MultiPartParser)

    def put(self, request, format=None):
        file_obj = request.data['file']
        self.handle_uploaded_file(file_obj)
        return Response(status=204)

    def handle_uploaded_file(self, ufile):
        filename = "{0}/{1}".format(settings.MEDIA_ROOT, ufile)
        with open(filename, "wb+") as target:
            for chunk in ufile.chunks():
                target.write(chunk)

curl command

curl -H "Content-Disposition: attachment; filename=try.py" -X PUT -F "file=@try.py" http://localhost:8000/api/fileupload/?filename=testing

try.py

from django.test import TestCase

# Create your tests here.

The next part is how to make it resumable.

Mox
  • 2,355
  • 2
  • 26
  • 42
  • Consider [this question](http://stackoverflow.com/questions/8249042/uploading-large-files-with-python-django) – Ross Rogers Feb 09 '16 at 23:13
  • @Ross Rogers, I have tried that. but getting errors. that method worked well for a form submission. But what I wanna create is an API for file upload. – Mox Feb 10 '16 at 03:11
  • 1
    Can you create a backend for [Resumable.js?](http://resumablejs.com/) – Ross Rogers Feb 10 '16 at 03:30
  • @Ross Rogers, No I need to decouple my frontend from backend. this API is not only used web browser, it will needs to be used by mobile devices too. Anyway, I managed to do a file upload, but the file is not being parsed properly. the header is saved together with the file. – Mox Feb 10 '16 at 04:48
  • If you create the backend API surface for Resumable.js, you can still use that same API on other platforms and not connect directly with Resuamble.js. You'll just be following a pattern that others have used. – Ross Rogers Feb 10 '16 at 16:15

0 Answers0