Merge Multiple PPTX file onto one PPTX Using pm2 on AWS

I currently have an app that runs on a linux AWS EC2 instance, it uses pm2 to stay up/reboot. Upon boot the use of fileApi.uploadFile() works just fine and then I use documentApi.join() no problems. Sometime around a day later it errors out when trying to upload the file. If I restart the app, it will work again. There are no logs of the failed attempt to hit the API in my groupDocs dashboard. Here is a code snippet of my upload function call:


const uploadFiles = async (files, userID, callBack, res) => {
  // construct FileApi
  await Promise.all(
    files.map(
      async (file) =>
        // read files one by one
        await new Promise((resolve, reject) =>
          fs.readFile(path.join(__dirname, `../Users/${userID}/${file.assetId}/${file.assetId}.pptx`),
            async (err, fileStream) => {
              if(err){
                console.log(err)
              } else {

                // create upload file request
                console.log("forming request");
               
                  let request = new groupdocs_merger_cloud.UploadFileRequest(
                    "/sutherlandTest/" + file.assetId + ".pptx",
                    fileStream,
                    myStorage
                    );
                    // upload file
                    console.log("request ", request);
                    try {
                      let response = await fileApi.uploadFile(request);
                      console.log(file.assetId + " file uploaded: " + response.uploaded.length);
                      
                    } catch (error) {
                      throw error.message;
                    }
                   resolve()
                  }

       
            }
          )
        )
    )
  );
  await mergeSlides(files, userID)
 
};

Any tips would be helpful.

@PeopleProdDev

We are looking into it and will guide you soon.

@PeopleProdDev

Apparently, it seems to be an auto refresh token feature related issue in GroupDocs.Merger Cloud SDK for Node.js. However, we have logged a ticket MERGERCLOUD-77 for further investigation and resolving the problem. Meanwhile, in this case, you can initialize API each time before using it.

Thank you. This would look like bringing this line:

let fileApi = groupdocs_merger_cloud.FileApi.fromConfig(config);

into the uploadFile function so fileApi gets initialized on every call, correct?

@PeopleProdDev

Yes, in the uploadFile function. However, we will also notify you as soon as we resolve the above logged ticket.

1 Like

@PeopleProdDev

Please note that we have fixed the token refresh issue in the GroupDocs.Merger Cloud SDK for Node.js and published the updated SDK 23.5 to NPM.

1 Like