Skip to main content
Participant
July 1, 2024
Question

unable to downlaod assets

  • July 1, 2024
  • 1 reply
  • 365 views

Hi I hope someone can help. I am following the tutorial onb the get started page for PDF Services. i am currently on the last step where I cannot generate a pdf.  the pdf get rendered but in XML saying "The request signature we calculated does not match the signature you provided. Check your key and signing method. " i have tried with auth headers and without nothing seems to work below is a snippet of the code 


export const checkCompressionStatus = async (jobId: string, token: string, clientId: string) => {
  console.log("id", jobId);
  // const url = `https://pdf-services.adobe.io/operation/compresspdf/${jobId}/status`;
  const url = jobId;
  console.log("url", url);

  try {
    const response = await fetch(url, {
      method: "GET",
      headers: {
        Authorization: `Bearer ${token}`,
        "x-api-key": clientId,
      },
    });
    console.log("res", response);

    if (!response.ok) {
      throw new Error("Failed to fetch compression status");
    }

    const data = await response.json();
    console.log("Compression status:", data);

    if (data.status === "in progress") {
      console.log("Status: in progress. Checking again...");
      // Recursive call to check status again after a delay (e.g., 2 seconds)
      await new Promise(resolve => setTimeout(resolve, 2000));
      return checkCompressionStatus(jobId, token, clientId); // Recursive call
    } else if (data.status === "done") {
      console.log("Compression job is done.");
      fetchPDFObject(data.asset.downloadUri, clientId, token);

      return data; // Return final status data
    } else if (data.status === "fail") {
      console.log("Compression job failed.");
      return data; // Return final status data
    } else {
      throw new Error("Unexpected status received");
    }
  } catch (error: any) {
    console.error("Error fetching compression status:", error.message);
    throw error; // Re-throw the error for further handling
  }
};




export const fetchPDFObject = async (url: string, clientId: string, token: string) => {
  console.log("token", token);
  console.log("assid", clientId);
  console.log("url", url);
  try {
    const response = await fetch(url, {
      method: "GET",
      //headers: {
      // Authorization: `Bearer ${token}`,
      //  "x-api-key": clientId
      //},
    });

    if (!response.ok) {
      throw new Error("Failed to fetch S3 object");
    }
    console.log("res", response);

    // Assuming you want to return the blob data for further processing
    const blob = await response.blob();

    // Create a URL for the blob
    const blobUrl = URL.createObjectURL(blob);

    // Create a link element
    const link = document.createElement("a");
    link.href = blobUrl;
    link.download = "downloaded-file.pdf"; // Set the default file name here

    // Append the link to the body
    document.body.appendChild(link);

    // Click the link to start the download
    link.click();

    // Clean up: Remove the link
    document.body.removeChild(link);

    return blob;
  } catch (error: any) {
    console.error("Error fetching S3 object:", error.message);
    throw error; // Re-throw the error for further handling
  }
};

any help whoudl be great! 

This topic has been closed for replies.

1 reply

Raymond Camden
Community Manager
Community Manager
July 8, 2024

If you log out that asset url for downloading and open it in a new tab, does it work ok?