Skip to main content
Best answer

How to make pdf file from stream response

  • December 5, 2022
  • 1 reply
  • 715 views

 Hey,

I make a trigger with files.

I send a request to the server and the response type is stream.

and when I tried to send it to z.stashfile I get a txt file with the content

how do I get a pdf file?

the contens is:

%PDF-1.5
%����..

Best answer by consist-adminBest answer by consist-admin

const options = {

    url: `https://XXXXXGetDocumentPreview?signFlowId=${bundle.inputData.signFlowId}`,

    method: 'GET',

    headers: {

      'Content-Type': 'application/pdf',

      Accept: 'application/pdf',

      Authorization: `Bearer ${bundle.authData.access_token}`,

      'X-Tenant': bundle.authData.realm,

    },

    raw: true,

    params: {},

    body: {},

  };

  const fileContent = await z.request(options)

    .then((response) => {

      response.throwForStatus();

      const file = response;

      return file;

    })

  const stash = await z.stashFile(fileContent);

  const fileInfo = {

    file: await z.dehydrateFile(hydrators.downloadFile, { url: stash }),

  };

  return fileInfo;

need to sent the response and not the response.content

 

View original
Did this topic help you find an answer to your question?
This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

1 reply

const options = {

    url: `https://XXXXXGetDocumentPreview?signFlowId=${bundle.inputData.signFlowId}`,

    method: 'GET',

    headers: {

      'Content-Type': 'application/pdf',

      Accept: 'application/pdf',

      Authorization: `Bearer ${bundle.authData.access_token}`,

      'X-Tenant': bundle.authData.realm,

    },

    raw: true,

    params: {},

    body: {},

  };

  const fileContent = await z.request(options)

    .then((response) => {

      response.throwForStatus();

      const file = response;

      return file;

    })

  const stash = await z.stashFile(fileContent);

  const fileInfo = {

    file: await z.dehydrateFile(hydrators.downloadFile, { url: stash }),

  };

  return fileInfo;

need to sent the response and not the response.content