Hello,
I am trying to using the cloud api for python to upload a pptx file, transform to pdf and then download into an specific folder. I am having problems in that final step, I cant see in any place my pdf downloaded and I cant move to an specific folder. Also the response is just an url should be? maybe there are another methods to download? here is my code:
here is my code:
def generate_and_save_pptx(self):
pptx_template_path = ‘panel/templates/originals/Prueba.pptx’
presentation = Presentation(pptx_template_path)
self.modify_presentation(presentation)
pdf_filename = f’{self.client.name} - {self.type_submission.name}_tutorial.pdf’
pptx_filename = f’{self.client.name} - {self.type_submission.name}_tutorial.pptx’
pdf_path = submission_directory_path(self, pdf_filename)
my_storage = “FilesToConvert”
pdf_cloud_path = f’FilesToConvert/{pdf_filename}’ # Usar / en lugar de \
with tempfile.NamedTemporaryFile(delete=False, suffix=".pptx") as temp_pptx:
temp_pptx_path = temp_pptx.name
presentation.save(temp_pptx_path)
try:
file_api = FileApi(Configuration(app_sid, app_key))
upload_request = UploadFileRequest(pptx_filename, temp_pptx_path, my_storage)
file_api.upload_file(upload_request)
except ApiException as e:
print(f"Error during upload: {e}")
try:
# Crear una instancia de la API
convert_api = ConvertApi.from_keys(app_sid, app_key)
# Configurar las opciones de conversión
convert_settings = ConvertSettings()
convert_settings.file_path = pptx_filename # El nombre del archivo subido
convert_settings.format = "pdf"
convert_settings.output_path = my_storage
# Crear la solicitud de conversión del documento
convert_request = ConvertDocumentRequest(convert_settings)
# Convertir el documento
convert_api.convert_document(convert_request)
except ApiException as e:
print(f"Error during transform: {e}")
try:
download_request = DownloadFileRequest(pdf_cloud_path, my_storage)
response = file_api.download_file(download_request)
if response:
shutil.move(response, pdf_path)
else:
print(f"Error during download")
except ApiException as e:
print(f"Error during download {e}")