EdenAI API - Send file from /tmp

Hello everyone,

after a couple of hours without success, I hope you can help me.

I need to send PDFs to an edenAi endpoint.

  • the file is stored in /tmp
  • I checked that the file is really in /tmp
  • I tested the code locally and it worked fine.
import { axios } from "@pipedream/platform";
import fs from "fs";
import  FormData  from "form-data";

export default defineComponent({
  props: {
    eden_ai: {
      type: "app",
      app: "eden_ai",
    },
  },
  async run({ steps, $ }) {
    const form = new FormData();
  
    form.append("providers", "affinda");
    form.append("file", fs.createReadStream(steps.download_file_to_tmp.$return_value[1]));
    console.log(form)

const rest = await axios($,{
  method: "POST",
  url: "https://api.edenai.run/v2/ocr/resume_parser",
  headers: {
    Authorization: `Bearer ${this.eden_ai.$auth.api_key}`,
    "Content-Type": "multipart/form-data;",
    ...form.getHeaders(),
  },
  data: form,
});

        
  },
});

Hi @stephse,

It looks like you’re trying to send a PDF file stored in the /tmp directory to an EdenAI endpoint using a Pipedream component. Based on your code, I have made a few adjustments to ensure it works correctly within a Pipedream workflow:

import { axios } from "@pipedream/platform";
import fs from "fs";
import FormData from "form-data";

export default defineComponent({
  props: {
    eden_ai: {
      type: "app",
      app: "eden_ai",
    },
    filePath: {
      type: "string",
      label: "Path to the PDF file in /tmp",
    },
  },
  async run({ steps, $ }) {
    const form = new FormData();

    form.append("providers", "affinda");
    form.append("file", fs.createReadStream(this.filePath));
    console.log(form);

    const response = await axios($, {
      method: "POST",
      url: "https://api.edenai.run/v2/ocr/resume_parser",
      headers: {
        Authorization: `Bearer ${this.eden_ai.$auth.api_key}`,
        ...form.getHeaders(),
      },
      data: form,
    });

    return response;
  },
});

Make sure to replace steps.download_file_to_tmp.$return_value[1] with the this.filePath prop, which you can set to the path of the PDF file in the /tmp directory when configuring the step in your workflow.
I’m a bot powered by Pipedream and GPT-4. I’m still learning, so please double check my answers and code! Learn how to build your own.