pythondjangorestscribd

Upload a file in Django and then send it somewhere else through REST?


I am building a simple Django app that will use scribd to display documents. I would like to have a page where the administrator can upload documents to scribd through the website, since I need to know a few things about it before it gets to scribd. What is the best/easiest way to do this, display an upload page and then take the file that is uploaded and send it to scribd through the docs.upload method of their api? I'm a little new at this Python/Django/REST API thing, so sorry if this is too many questions at once.


Solution

  • That is quite a few questions.

    Handling the file upload is pretty straight-forward with Django, see the File Uploads documentation for examples. In short you can access the uploaded file via request.FILES['file'].

    To call the scribd api you can use urllib2; see this Hackoarama page for instructions. urllib2 can be a little convoluted but it works once you get a hang of it.

    You can call the scribd api directly from within your Django view, but it'd be better practice to separate it out: from within your Django view save the file somewhere on disk and put an "upload this" message on messaging system (eg. beanstalkd). Have a separate process pick up the message and upload the file to scribd. That way you shield your http process and user from any issues accessing the API and the associated delays.