简体   繁体   English

将 PDF 文件从 Django 网站发送到 LogicalDOC

[英]Send PDF file from Django website to LogicalDOC

I'm developing my Django website since about 2 months and I begin to get a good global result with my own functions.我从大约 2 个月开始开发我的Django website ,我开始使用我自己的功能获得良好的全球结果。 But, now I have to start a very hard part (to my mind) and I need some advices, ideas before to do that.但是,现在我必须开始一个非常困难的部分(在我看来),我需要一些建议和想法才能做到这一点。

My Django website creates some PDF files from HTML templates with Django variables.我的 Django 网站使用 Django 变量从 HTML 模板创建了一些 PDF 文件。 Up to now, I'm saving PDF files directly on my Desktop (in a specific folder) but it's completely unsecured.到目前为止,我将 PDF 文件直接保存在我的桌面上(在特定文件夹中),但它是完全不安全的。 So, I installed another web application which is named LogicalDoc in order to save PDF file directly on this application .因此,我安装了另一个名为LogicalDoc Web 应用程序,以便直接在此应用程序上保存 PDF 文件 PDF files are created and sent to LogicalDoc. PDF 文件被创建并发送到 LogicalDoc。

LogicalDoc owns 2 API : SOAP and REST ( http://wiki.logicaldoc.com/rest/#/ ) and I know that Django could communicate with REST method. LogicalDoc 拥有 2 个 API:SOAP 和 REST( http://wiki.logicaldoc.com/rest/#/ ),我知道 Django 可以与 REST 方法进行通信。

I'm reading this part of Django documentation too in order to understand How I can process :https://docs.djangoproject.com/en/dev/topics/http/file-uploads/我也在阅读 Django 文档的这一部分,以了解如何处理:https ://docs.djangoproject.com/en/dev/topics/http/file-uploads/

I made a scheme in order to understand what I'm exposing :我制定了一个计划以了解我所暴露的内容:

在此处输入图片说明

Then, I write a script which makes some things :然后,我写了一个脚本来做一些事情:

  • When the PDF file is created, I create a folder inside LogicalDoc which takes for example the following name : lastname_firstname_birthday创建 PDF 文件后,我在 LogicalDoc 中创建了一个文件夹,例如使用以下名称:lastname_firstname_birthday

  • Two possibilities : If the folder exists,I don't create a new folder, else I create it.两种可能性:如果文件夹存在,我不创建新文件夹,否则我创建它。

  • Once it's done, I send the PDF file directly inside the folder by comparing PDF name with folder name to do that完成后,我通过将 PDF 名称与文件夹名称进行比较来将 PDF 文件直接发送到文件夹内

I have some questions about this process :我对这个过程有一些疑问:

  • Firstly, is it possible to make this kind of things ?首先,有可能做这种事情吗?

  • Is it hard to do that ?这样做很难吗?

  • What kind of advices could you give me ?你能给我什么样的建议?

Thank you so much !非常感谢 !

PS : If you need some part of my script, mainly PDF creating part, I can post it just after my question ;) PS:如果您需要我的脚本的某些部分,主要是PDF创建部分,我可以在我提出问题后立即发布;)

An idea is pretty simple, however it always requires some practice.一个想法很简单,但它总是需要一些练习。 I strongly advice you to use REST api and forget about SOAP as the only thing it can bring to you - is 'pain' :)我强烈建议您使用 REST api 并忘记 SOAP,因为它能给您带来的唯一事情是“痛苦”:)

If we check documentation, document/create it gives next information.如果我们检查文档, 文档/创建它会提供下一个信息。

  1. Endpoint we have to communicate with.我们必须与之通信的端点。 [protocol]://[server]:[port]/document/create [协议]://[服务器]:[端口]/document/create
  2. HTTP method to use - POST要使用的 HTTP 方法 - POST
  3. List of parameters to provide with your request: body , document , content与您的请求一起提供的参数列表: bodydocumentcontent

Even more, you can test API by clicking on "Try it out" button and check requests in "Network" tab of your browser (if you open Developer Tools)更重要的是,您可以通过单击“试用”按钮并在浏览器的“网络”选项卡中检查请求来测试 API(如果您打开开发人员工具)

I am not sure what kind of metadata do you have to provide in 'document' parameter but what I know you can easy get an idea of what should be done by testing it and putting XML or JSON data into 'document' parameter.我不确定您必须在“文档”参数中提供什么样的元数据,但我知道您可以通过测试它并将 XML 或 JSON 数据放入“文档”参数中来轻松了解应该做什么。

Content is an array of bytes transferred to the server (which would be your file).内容是传输到服务器的字节数组(这将是您的文件)。

To sum up, a request to 'document/create' uri will be simple总而言之,对“文档/创建”uri 的请求将很简单

body = { 'headers': {},'object': {},}
document = "<note>data</note>"
content=open('report.xls', 'rb') #r - reading, b - binary
r = requests.post('http://logicaldoc/document/create', body=body, document=document, content=content)

Please keep in mind that file transferring requests take time and sometimes you may get timeout exception.请记住,文件传输请求需要时间,有时您可能会遇到超时异常。 Your code will stop and will be waiting for response, so it may be a good idea to get some practice with asyncio or celery.您的代码将停止并等待响应,因此使用 asyncio 或 celery 进行一些练习可能是个好主意。 Just keep in mind those kind of possible issues.请记住那些可能的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM