I am currently trying to extract the images from a document that the user is uploading into the media repository of my Django app. The code that currently works for me is:
html = pypandoc.convert(
tmp_loc,
'html5',
extra_args=['--extract-media=']
)
This correctly extracts the images into the media directory as image01.jpg
In HTML the img src is:
<img src="/media/image01.jpg" />
Now the problem is that when the user uploads another docx which also has a image it replaces the previous image when it is uploaded as it is also saved by the name image01.jpg.
To solve this problem I thought we could just create a new folder in the media repository and name of the new folder would be the doc-name. So now the code looks like this:
html = pypandoc.convert(
tmp_loc,
'html5',
extra_args=['--extract-media=/media/<some_doc_name>']
)
But the moment I run this I get the following error:
Pandoc died with exitcode "1" during conversion: b'pandoc: /media/docs: createDirectory: permission denied (Permission denied)\n'
Could someone guide me what is going wrong? How to fix this? Any alternative methods of solving this problem would also be appreciated!!
I am using the Pypandoc module in python.