Essex
Essex

Reputation: 6128

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. 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. Up to now, I'm saving PDF files directly on my Desktop (in a specific folder) but it's completely unsecured. So, I installed another web application which is named LogicalDoc in order to save PDF file directly on this application. PDF files are created and sent to LogicalDoc.

LogicalDoc owns 2 API : SOAP and REST (http://wiki.logicaldoc.com/rest/#/) and I know that Django could communicate with REST method.

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/

I made a scheme in order to understand what I'm exposing :

enter image description here

Then, I write a script which makes some things :

I have some questions about this process :

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 ;)

Upvotes: 2

Views: 479

Answers (1)

taras
taras

Reputation: 3705

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' :)

If we check documentation, document/create it gives next information.

  1. Endpoint we have to communicate with. [protocol]://[server]:[port]/document/create
  2. HTTP method to use - POST
  3. List of parameters to provide with your request: body, document, content

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)

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.

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

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. Just keep in mind those kind of possible issues.

Upvotes: 2

Related Questions