Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 从Django InMemoryUploadedFile解析pdf_Python_Django_Pdf - Fatal编程技术网

Python 从Django InMemoryUploadedFile解析pdf

Python 从Django InMemoryUploadedFile解析pdf,python,django,pdf,Python,Django,Pdf,接收到使用Django rest_框架的pdf文件。我尝试了几种方法来解析传入文件中的内容 curl-vX POST-d@10_CSS\(1.pdf--标题“内容类型:应用程序/pdf”---标题“内容配置:附件;文件名=10_CSS.pdf” PDFSyntaxError:否/根对象!-这真的是PDF吗 AttributeError:“str”对象没有属性“seek” PDFSyntaxError:否/根对象!-这真的是PDF吗 我尝试了几个pdf文件,结果都是一样的。当我在将pdf文件发送到

接收到使用Django rest_框架的pdf文件。我尝试了几种方法来解析传入文件中的内容

curl-vX POST-d@10_CSS\(1.pdf--标题“内容类型:应用程序/pdf”---标题“内容配置:附件;文件名=10_CSS.pdf”

PDFSyntaxError:否/根对象!-这真的是PDF吗

AttributeError:“str”对象没有属性“seek”

PDFSyntaxError:否/根对象!-这真的是PDF吗

我尝试了几个pdf文件,结果都是一样的。当我在将pdf文件发送到应用程序之前尝试解析它时,它解析得很好**如何从MemoryUploadedFile中解析pdf文件?

我猜您正在使用:

parser_classes = (FileUploadParser,)
在这种情况下,文件中会包含标题(--header“Content-Disposition:attachment;filename=10_css.pdf”)

我建议您使用
MultiPartParser
,不要发送内容处置头

我猜您正在使用:

parser_classes = (FileUploadParser,)
在这种情况下,文件中会包含标题(--header“Content-Disposition:attachment;filename=10_css.pdf”)

我建议您使用
MultiPartParser
,不要发送内容处置头

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)                                
parser_classes = (FileUploadParser,)