Parse pdf from Django InMemoryUploadedFile
<p>Received a pdf file using Django rest_framework. I tried several ways to parse content from incoming file.</p>

<blockquote>
  <p>curl -vX POST <a href="http://127.0.0.1:8000/documents/" rel="nofollow">http://127.0.0.1:8000/documents/</a> -d @10_CSS\ (1).pdf --header "Content-Type: application/pdf" --header "Content-Disposition: attachment; filename=10_css.pdf"</p>
</blockquote>

<pre><code>def create(self, request):        
    file_ = request.FILES['file'] 

    parser = PDFParser(file_)     
    document = PDFDocument(parser)
</code></pre>

<blockquote>
  <p>PDFSyntaxError: No /Root object! - Is this really a PDF?</p>
</blockquote>

<pre><code>def create(self, request):        
    file_ = request.FILES['file'] 

    parser = PDFParser(file_.read())     
    document = PDFDocument(parser)
</code></pre>

<blockquote>
  <p>AttributeError: 'str' object has no attribute 'seek'</p>
</blockquote>

<pre><code>def create(self, request):        
    utf8_file = codecs.EncodedFile(request.FILES['file'], "utf-8")
    with open('/tmp/whatever.pdf', 'wb+') as destination:         
        for chunk in request.FILES['file'].chunks():              
            destination.write(chunk)                              

    file_ = open('/tmp/whatever.pdf', 'rb')                       
    parser = PDFParser(file_)                                     
    document = PDFDocument(parser)                                
</code></pre>

<blockquote>
  <p>PDFSyntaxError: No /Root object! - Is this really a PDF?</p>
</blockquote>

<p>I tried several pdf files with the same result. And when I tried to parse a pdf file before I sent it to my application it parsed well. **How to parse a pdf file from <code>InMemoryUploadedFile</code>?</p>