From dc9ed11f512111905bdc572563d31e53a32bf367 Mon Sep 17 00:00:00 2001 From: Eric Shore Date: Fri, 30 Aug 2024 13:32:00 -0500 Subject: [PATCH] Update uploadAndMergePDFs.gs Simplify upload and merge script --- .../Merge PDFs/uploadAndMergePDFs.gs | 21 +++---------------- 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/Google Apps Script/Advanced Integrations/Merge PDFs/uploadAndMergePDFs.gs b/Google Apps Script/Advanced Integrations/Merge PDFs/uploadAndMergePDFs.gs index bfd7624..4190dda 100644 --- a/Google Apps Script/Advanced Integrations/Merge PDFs/uploadAndMergePDFs.gs +++ b/Google Apps Script/Advanced Integrations/Merge PDFs/uploadAndMergePDFs.gs @@ -1,7 +1,7 @@ function uploadAndMergePDFs(pdfFiles) { // Replace with your actual API key const apiKey = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"; - + const uploadUrl = "https://api.pdfrest.com/upload"; const mergeUrl = "https://api.pdfrest.com/merged-pdf"; @@ -33,9 +33,6 @@ function uploadAndMergePDFs(pdfFiles) { typeArr.push("id"); } - // Wait for all uploads to complete - uploadedFiles.forEach(fileId => waitForUploadCompletion(fileId)); - // Prepare merge request data const mergeData = { @@ -66,28 +63,16 @@ function uploadAndMergePDFs(pdfFiles) { return (mergedPdfInfo.outputId); } -function checkUploadStatus(fileId) { - const options = { - "method": "get", - }; - const response = UrlFetchApp.fetch(`https://api.pdfrest.com/resource/${fileId}?format=info`, options); - const data = JSON.parse(response.getContentText()); - return data.size > 0; -} - -function waitForUploadCompletion(fileId) { - while (!checkUploadStatus(fileId)) { - Utilities.sleep(1000); // Wait 1 second before checking again - } -} function getFile(fileId, folderId) { const options = { "method": "get", "responseType": UrlFetchApp.BLOB, // Specify response type as blob }; + const response = UrlFetchApp.fetch(`https://api.pdfrest.com/resource/${fileId}?format=file`, options); const pdfBlob = response.getBlob(); // Directly get the blob from the response + const folder = DriveApp.getFolderById(folderId); const result = folder.createFile(pdfBlob); console.log("Merged PDF downloaded!");