Hello
I am using Aspose.Words Cloud SDK for Python for file conversion, and I can see it in the cloud storage.
How can I download the file, or even directly read the file with Python?
Hello
I am using Aspose.Words Cloud SDK for Python for file conversion, and I can see it in the cloud storage.
How can I download the file, or even directly read the file with Python?
You can use DownloadFile API to download files from cloud storage and here is Aspose.Words Cloud SDK for Python sample code for reference.
remoteFolder = 'Temp'
localFolder = 'C:/Temp'
remoteFileName= 'revisions.docx'
#download file from storage
request_download=asposewordscloud.models.requests.DownloadFileRequest(remoteFolder + '/' + remoteFileName)
response_download = words_api.download_file(request_download)
copyfile(response_download, localFolder + '/' +"output.docx")
@tilal.ahmad Thank you again. I have one more question:
How to use the DownloadFile API with Python? I donāt know how to construct the āAuthorizationā, the server always response [401 Authorization token is invalid or expired. ].
Please find the complete sample code to convert DOCX to PDF without Word installed in Python and download output file from cloud storage using Aspose.Words Cloud API. Hopefully, it will help you to accomplish the task.
However, if you still face the issue then please share your sample code along with the credentials. Please share the credentials via a private message. For private message, click on my user icon and opt the message tab with the required information. Kindly remove āRE:ā from the title as well. We will investigate the issue and will update you.
# For complete examples and data files, please go to https://github.com/aspose-words-cloud/aspose-words-cloud-python
# Import module
import asposewordscloud
import asposewordscloud.models.requests
from shutil import copyfile
# Please get your Client ID and Secret from https://dashboard.aspose.cloud.
client_id = 'xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx'
client_secret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
# Initiate API
words_api = asposewordscloud.WordsApi(client_id,client_secret)
words_api.api_client.configuration.host='https://api.aspose.cloud'
inputFileName = 'C:/Temp/02_pages.docx'
remoteFileName = 'DocumentSaveAs.docx'
outputFileName = 'DocumentSaveAs.pdf'
localFolder = 'C:/Temp'
#upload input file to storage
request_upload = asposewordscloud.models.requests.UploadFileRequest(open(inputFileName,'rb'),remoteFileName)
response_upload = words_api.upload_file(request_upload)
#Convert DOCX to PDF and save to storage
save_options = asposewordscloud.SaveOptionsData(save_format='pdf', file_name=outputFileName)
request_conversion = asposewordscloud.models.requests.SaveAsRequest(remoteFileName, save_options)
response_conversion = words_api.save_as(request_conversion)
print(response_conversion)
#download file
request_download=asposewordscloud.models.requests.DownloadFileRequest(outputFileName)
response_download = words_api.download_file(request_download)
copyfile(response_download, localFolder + '/' + outputFileName)