We're sorry AsposeCloud doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.cloud

How convert Word document and download output file in 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?

@JeffSartorius

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")
1 Like

@tilal.ahmad
Thank you. It works, and the copyfile function is imported from shutil.

1 Like

@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. ].

@JeffSartorius

Please find the complete sample to download a file from cloud storage. 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 os
import asposewordscloud
import asposewordscloud.models.requests
from shutil import copyfile


# Please get your Client ID and Secret from https://dashboard.aspose.cloud.
client_id='xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx'
client_secret='xxxxxxxxxxxxxxxxxxxxxxxx'

words_api = asposewordscloud.WordsApi(client_id,client_secret)
words_api.api_client.configuration.host='https://api.aspose.cloud'

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")