Convert DOC to PDF in Node.js using Aspose.Words Cloud throws error: ‘The specified key does not exist'

Response from ApI
key is correct but I get below response
{ message: ‘No HTTP resource was found that matches the request URI `http://api .aspose.cloud/v1.1/test.doc/saveAs?AppSid=41cbf44e-2bb8-4bd4-ab3a-58e5b569ddbd` .’, code: 404 }

My Usage logs

Error: Error while loading file ‘test.doc’ from storage: AmazonS3 exception: Error ‘The specified key does not exist.’, Bucket ‘afc-filestorage’, FilePath ‘64628/85c10523-b990-402f-893c-bae45d969a8e/test.doc’ => Error while loading file ‘test.doc’ from storage: AmazonS3 exception: Error ‘The specified key does not exist.’, Bucket ‘afc-filestorage’, FilePath ‘64628/85c10523-b990-402f-893c-bae45d969a8e/test.doc’ => AmazonS3 exception: Error ‘The specified key does not exist.’, Bucket ‘afc-filestorage’, FilePath ‘64628/85c10523-b990-402f-893c-bae45d969a8e/test.doc’. Method: Save the document as… Parameters: name ‘test.doc’,saveOptionsData ‘Aspose.Words.Cloud.DTO.Saving.PdfSaveOptionsData’,folder ‘’


This Topic is created by sohail.aspose using the Email to Topic plugin.

@vinita.bhandari

Thank you for contacting Aspose Support.

http://api .aspose.cloud/v1.1/test.doc/saveAs?AppSid=41cbf44e-2bb8-4bd4-ab3a-58e5b569ddbd

This URL is incorrect. Please ensure you are using our maintained Aspose.Words Node.js SDK. The following command installs Aspose.Words-Cloud via NPM

npm install asposewordscloud --save

Please contact us if there are any problems.

@mateensajjad

Thank you for replying

I already installed asposewordscloud using mentioned command

npm install asposewordscloud --save

If I use above command so I don’t have to use SDK?

@vinita123

If I use above command so I don’t have to use SDK?

Yes. npm install asposewordscloud --save is a convenient way to integrate SDK into your project.

I am using npm install asposewordscloud --save

Still getting below error

Response from ApI
key is correct but I get below response
{ message: ‘No HTTP resource was found that matches the request URI http://api .aspose.cloud/v1.1/test.doc/saveAs?AppSid=41cbf44e-2bb8-4bd4-ab3a-58e5b569ddbd .’, code: 404 }

My Usage logs

Error: Error while loading file ‘test.doc’ from storage: AmazonS3 exception: Error ‘The specified key does not exist.’, Bucket ‘afc-filestorage’, FilePath ‘64628/85c10523-b990-402f-893c-bae45d969a8e/test.doc’ => Error while loading file ‘test.doc’ from storage: AmazonS3 exception: Error ‘The specified key does not exist.’, Bucket ‘afc-filestorage’, FilePath ‘64628/85c10523-b990-402f-893c-bae45d969a8e/test.doc’ => AmazonS3 exception: Error ‘The specified key does not exist.’, Bucket ‘afc-filestorage’, FilePath ‘64628/85c10523-b990-402f-893c-bae45d969a8e/test.doc’. Method: Save the document as… Parameters: name ‘test.doc’,saveOptionsData ‘Aspose.Words.Cloud.DTO.Saving.PdfSaveOptionsData’,folder ‘’

@vinita123

I am assuming you are using Aspose Cloud Storage and are not using any third party storage.

Please consider following code:

const { WordsApi, PostDocumentSaveAsRequest, SaveOptionsData } = require("asposewordscloud");

wordsApi = new WordsApi(AppSid, AppKey);

var request = new PostDocumentSaveAsRequest({
    name: "fileStoredInCloud.doc",
    saveOptionsData: new SaveOptionsData(
        {
            saveFormat: "pdf",
            fileName: "destination.pdf"
        })
});

wordsApi.postDocumentSaveAs(request).then((result) => {    
    console.log(result.body.code);    
}).catch(function(err) {
    // Deal with an error
    console.log(err);
}); 

PostDocumentSaveAsRequest API assumes that input file fileStoredInCloud.doc exist at Aspose Cloud Storage.

You are getting following error because input file test.doc does not exist at Aspose Cloud Storage.

{ message: 'Error while loading file \'test.doc\' from storage: AmazonS3 exception: Error \'The specified key does not exist.\', Bucket \'afc-filestorage\', FilePath \'9971/24d10606-81da-4fc2-8faf-c463c77e9539/test.doc\'',
  code: 400 }

First, upload the file using Aspose Cloud UI or using Aspose.Storage File Upload API to Aspose Cloud Storage.

Please use PUT /words/convert API if you want to send input file in request body and wants API to return converted file in API response.

Please let us know if you need any further information.

@vinita123

As an update, please note since Aspose.Words Cloud 19.4 release, we have introduced an improved API version V4.0. In this API version, we have changed PUT to POST (and vice versa). Now, all idempotent methods are PUT and non-idempotent ones are POST. So the SaveAs method is PUT now. And now Aspose.Words Cloud has its own API methods for storage processing. Please find the sample updated code.


const { WordsApi, UploadFileRequest, SaveAsRequest, SaveOptionsData } = require("asposewordscloud");
var fs = require('fs');

// Please get your Client ID and Client Secret from https://dashboard.aspose.cloud/.
wordsApi = new WordsApi("xxxxxx-xxxx-xxxx-xxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxxxxxxxx");

const localFile = "C:/Temp/02_pages.docx";
const remoteFileName = "02_pages.docx";
const resultFileName = "02_pagesoutput.pdf";
const remoteFolder = "Temp";

//Upload File
const uploadRequest = new UploadFileRequest({
		fileContent: fs.createReadStream(localFile),
		path: remoteFolder + "/" + remoteFileName
});


wordsApi.uploadFile(uploadRequest).then((resultApi) => {
		console.log('uploaded...');	
		}).catch(function(err) {
		// Deal with an error
		console.log(err);
});


//Convert
 const request = new SaveAsRequest({
                    name: remoteFileName,
                    saveOptionsData: new SaveOptionsData({
                        saveFormat: "pdf",
                        fileName: resultFileName
                    }),
                    folder: remoteFolder
                });
                       

wordsApi.saveAs(request).then((result) => {    
		console.log(result.body);   
		console.log('Completed...');	
		}).catch(function(err) {
		// Deal with an error
		console.log(err);
});