I have a docx file stored in cloud storage and I want to convert it to PDF and store it there as well using a python cloud function. Meaning I don't want to download the file, convert it on my local machine and upload it back to storage, so simple stuff like the following code can't be used:
from docx import document
from docx2pdf import convert
doc = document()
doc.save('some_path')
convert(docx_path, pdf_path)
I tried using io.BytesIO like the following example:
import io
from docx import document
from docx2pdf import convert
file_stream = io.BytesIO()
file_stream_pdf = io.BytesIO()
doc = document()
doc.save(file_stream)
file_stream.seek(0)
convert(file_stream, file_stream_pdf)
but I am getting the error:
TypeError: expected str, bytes or os.PathLike object, not BytesIO.
I know convert receives paths as strings, but I dont know how to use BytesIO in this case.
Is there a simple way to fix what I have done so far or perhaps a different approach?