Получил pdf-файл, используя Django rest_framework. Я попробовал несколько способов разобрать содержимое из входящего файла.Parse pdf from Django InMemoryUploadedFile
curl -vX POST http://127.0.0.1:8000/documents/ -d @10_CSS\ (1).pdf --header "Content-Type: application/pdf" --header "Content-Disposition: attachment; filename=10_css.pdf"
def create(self, request):
file_ = request.FILES['file']
parser = PDFParser(file_)
document = PDFDocument(parser)
PDFSyntaxError: No /Root object! - Is this really a PDF?
def create(self, request):
file_ = request.FILES['file']
parser = PDFParser(file_.read())
document = PDFDocument(parser)
AttributeError: 'str' object has no attribute 'seek'
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)
PDFSyntaxError: No /Root object! - Is this really a PDF?
Я попробовал несколько файлов PDF с тем же результатом. И когда я попытался разобрать pdf-файл, прежде чем отправить его в мое приложение, он хорошо разбирается. ** Как разобрать pdf-файл с InMemoryUploadedFile
?