Home > OS >  How to download a file to local from Aspose.Cloud?
How to download a file to local from Aspose.Cloud?

Time:08-05

I am trying to convert doc to pdf using Aspose.Words-Cloud but the conversion API uploads the converted file to cloud and I can't find a clear way to download it to local via code.

This is the code provided by Aspose.Cloud,

private static void downloadToLocal(Configuration config, string path) 
{ 
  StorageApi storageApi = new StorageApi(config);
  GetDownloadRequest request = new GetDownloadRequest(); 
  request.Path = path; 
  request.Storage = null; 
  request.VersionId = null; 
  var response = storageApi.GetDownload(request); 
}

but it is not clear which library StorageApi and GetDownloadRequest are a part of.

CodePudding user response:

It seems you are using some old SDK version of Aspose.Words Cloud. Please note since 19.4 release, now Aspose.Words Cloud API has its own storage methods for storage operations. Please use the latest version of Aspose.Words Cloud SDK for .NET from NuGet to download a file to a local drive from cloud storage as follows.

P.S: I am a developer evangelist at aspose.cloud.

public static async Task DownloadStorageFile_Word()
{

    Aspose.Words.Cloud.Sdk.Configuration config = new Aspose.Words.Cloud.Sdk.Configuration();
    config.ClientId = ClientId;
    config.ClientSecret = ClientSecret;

    Aspose.Words.Cloud.Sdk.WordsApi wordsApi = new Aspose.Words.Cloud.Sdk.WordsApi(config);
    // Download a File from Cloud Storage
    var downloadRequest = new Aspose.Words.Cloud.Sdk.Model.Requests.DownloadFileRequest("Output.pdf",null,null);
    var actual = await wordsApi.DownloadFile(downloadRequest);
    var fileStream = System.IO.File.Create(@"C:\Temp\Output.pdf");
    actual.CopyTo(fileStream);
    fileStream.Close();
}
  • Related