Best answer

How to make pdf file from stream response

  • 5 December 2022
  • 1 reply
  • 534 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
%����..

icon

Best answer by consist-admin 6 December 2022, 17:51

View original

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