PDF file contents corrupted?

I am using Aspose to store a PDF, and that works well. I use S3 as my storage so if I download the file directly from S3 the file works fine. However, I cannot get a well formed PDF document when I’m using the node words api. What I’m doing is pretty simple, but the contents I get is never well formed and the file will not open with Preview on MacOS 12.5.1

Here is what I’m doing.

const downloadFileResponse = await wordsApi.downloadFile(
    new model.DownloadFileRequest({
      path: "/path/to/pdf/file.pdf",
      storageName: asposeFileStorage,
    })
  );

  fs.writeFileSync(
    `/path/to/local/file/file.pdf`,
    downloadFileResponse.body
  );

“It may be damaged or a format that preview does not recognize” is the error I get trying to open the file after writing to disk.

This seems pretty simple, is there something obvious I’m doing wrong?

Using CURL to directly get the file causes the same problem with the downloaded PDF. I tried this:

curl -X GET "https://api.aspose.cloud/v4.0/words/storage/file/pathtofilemyfile.pdf?storageName=s3-storage-test" -H "accept: multipart/form-data" -H 'Authorization: Bearer REDACTED' --output testing.pdf

@jamesalonso

Please double check that you are using the latest version of the Aspose.Words Cloud SDK for Node.js. I have tested the scenario as follows and unable to notice any issues.


const { WordsApi, DownloadFileRequest } = require("asposewordscloud");
var fs = require('fs');

const download = async () => {
// Get Customer ID and Customer Key from https://dashboard.aspose.cloud/
wordsApi = new WordsApi("XXXXX-XXXX-XXXX-XXXX-XXXXXXXXXX", "XXXXXXXXXXXXXXXX");

try {
const request = new DownloadFileRequest({
                    path: "02_pages.pdf",
                    storage: "MyDB_Storage"                    
                });
const outputFile = "C:/Temp/Output.pdf";
const result = await wordsApi.downloadFile(request);  

fs.writeFileSync(outputFile, result.body);
} catch (err) {
throw err;
}
}

download()
.then(() => {
console.log("document downloaded.... successfully");
})
.catch((err) => {
console.log("Error occurred while downloading the Word document:", err);
})

I will double check, but I see the same issue with the CURL command I posted about 30 minutes ago. And that isn’t using any client library at all.

Not sure why that works if CURL fails, but the updated client library solved the issue.

@jamesalonso

It is good to know that your Node.js issue is resolved. In reference to the cURL issue, it is working fine at my end.

curl -X GET "https://api.aspose.cloud/v4.0/words/storage/file/02_pages.pdf?storageName=MyDB_Storage" 
-H "accept: multipart/form-data" 
-H "Authorization: Bearer eyJhbGciOiJSUz.....3QRZzQ" 
--output C:/Temp/output.pdf