• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
3

PDF Extract Service API Fails with BAD_PDF_FILE_TYPE

New Here ,
May 15, 2024 May 15, 2024

Copy link to clipboard

Copied

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

TOPICS
PDF Extract API , REST APIs

Views

120

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 15, 2024 May 15, 2024

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
May 16, 2024 May 16, 2024

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 16, 2024 May 16, 2024

Copy link to clipboard

Copied

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,

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
May 16, 2024 May 16, 2024

Copy link to clipboard

Copied

Ah shoot I'm sorry - I'm at a conf and kinda rushed and I sent you some old sample code. I'm going to try to find you a better sample.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
May 16, 2024 May 16, 2024

Copy link to clipboard

Copied

Ok, check out my ServicesWrapper -> https://github.com/cfjedimaster/document-services-demos/blob/main/serviceswrapper/ServicesWrapper.js. This is a library I built to use the REST API as I preferred it to the SDK. It's not a sample hello world sample, but the code in there should help you. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 16, 2024 May 16, 2024

Copy link to clipboard

Copied

LATEST

Hi Raymond,

 

your code samples worked perfectly, thank you for the help!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources