5

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 "[email protected]" 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.

5
  • Consider this question Commented Feb 9, 2016 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. Commented Feb 10, 2016 at 3:11
  • 1
    Can you create a backend for Resumable.js? Commented Feb 10, 2016 at 3: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. Commented Feb 10, 2016 at 4: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. Commented Feb 10, 2016 at 16:15

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.