Skip to main content
Participant
May 16, 2024
Question

PDF Extract Service API Fails with BAD_PDF_FILE_TYPE

  • May 16, 2024
  • 1 reply
  • 620 views

I'm receiving Error Code: "BAD_PDF_FILE_TYPE" when using the Check Status request with Postman, despite the mime type of my file being "application/pdf" and the file being an actual pdf document.

Where am I going wrong?

 

Thanks

This topic has been closed for replies.

1 reply

Participant
May 16, 2024

I'm pulling my hair out over this, this is my code to send the file to Adobe servers

module.exports = async (file, uploadURL) => {
  try {
    const myHeaders = new Headers();
    myHeaders.append("Content-Type", "application/pdf");

    const formdata = new FormData();
    formdata.append("file", JSON.stringify(file));
    console.log(file);

    const requestOptions = {
      method: "PUT",
      headers: myHeaders,
      body: formdata,
      redirect: "follow",
    };

    const res = await fetch(uploadURL, requestOptions);
    console.log(res?.statusText);
  } catch (error) {
    console.log(error);
  }
};

and this is what the file looks like when i log it to the console

{
  name: 'Label.pdf',
  data: <Buffer 25 50 44 46 2d 31 2e 36 0a 25 c3 a4 c3 bc c3 b6 c3 9f 0a 32 20 30 20 6f 62 6a 0a 3c 3c 2f 4c 65 6e 67 74 68 20 33 20 30 20 52 2f 46 69 6c 74 65 72 2f ... 39732 more bytes>,
  size: 39782,
  encoding: '7bit',
  tempFilePath: '',
  truncated: false,
  mimetype: 'application/pdf',
  md5: '6272657ca193f14546e27bcfa8226a76',
  mv: [Function: mv]
}

 Any help would be much appreciated

Raymond Camden
Community Manager
Community Manager
May 16, 2024

You don't stringify the binary data when you send it. I can show you Node code for how I do this with JavaScript, see: https://github.com/cfjedimaster/document-services-demos/blob/main/rest/test1.js

Participant
May 16, 2024

Hi Raymond, thanks for the reply.

 

I'm trying to use your code, however I'm missing a private key. Checking the Projects page, it shows all other credentials however I can't see a private key, where would I find that?

 

Thanks,