algoo / preview-generator

generates previews of files with cache management
https://pypi.org/project/preview-generator/
MIT License
228 stars 51 forks source link

How to display preview image in Django template once you have its path? #146

Open vbroskas opened 4 years ago

vbroskas commented 4 years ago

When I use preview-generator on a .pdf it returns a path: /tmp/preview_cache/66736b859e3928a04fcacedead81224a-256x256.jpeg

What do I need to do in order to display the preview image in a django template? I'm guessing I need to set it up so that when the preview image is generated it is stored in /media/, and then I should be able to get the URL for it.

Can any other Django users give me some clarification on the best way to do this? Thanks for any help!

AtulCIS commented 4 years ago

Hi @vbroskas I have done this in Django. I have shown the preview of the pdf file. So I have created an iframe and added the pdf URL with appending domain name. It means I have returned DOMAIN_NAME + the_path of file. In your case you are using a temp folder, I am suggesting you store the file in Django static folder and then return the path. You can create an image tag with a returned URL and append it to the body.