Why Am I Receiving an 'ENOENT: No Such File or Directory' Error when Emailing a File from the /tmp Directory?

This topic was automatically generated from Slack. You can find the original thread here.

I’m attempting to email myself a file from the /tmp directory. I can list the file and see it exists but when I try and email it to myself I get an error saying ENOENT: no such file or directory, open 'tmp/file_name'

To email yourself a file from the /tmp directory using Pipedream, you need to ensure that you are correctly referencing the file path. The error ENOENT: no such file or directory, open 'tmp/file_name' suggests that the file path might be incorrect. The correct path should start with a forward slash, like /tmp/file_name. Here’s an example of how you can send an email with a file attachment from the /tmp directory using the Email API in a Pipedream component: import { axios } from "@pipedream/platform"; export default defineComponent({ props: { email: { type: "app", app: "email", }, }, async run({ steps, $ }) { const filePath = '/tmp/your_file_name'; // Ensure the file path is correct // Read the file from /tmp const fileContent = require('fs').readFileSync(filePath); // Send the email with the file attachment const options = { subject: 'Your subject here', text: 'Your text here', attachments: [ { filename: 'your_file_name', // Name of the file to be attached content: fileContent, // File content }, ], }; $.send.email(options); }, }); ### Key Points: - Ensure the file path is correctly specified as /tmp/your_file_name. - Use Node.js fs module to read the file content. - Attach the file content to the email using the attachments option. If you continue to encounter issues, please double-check the file path and ensure the file exists in the /tmp directory. If the problem persists, feel free to reach out for further assistance.

I’m trying to make this request with axios using the payload I’ve saved to the /tmp/ directory. The payload is large and I run out of memory in my pipedream workflow. Can I somehow stream this in to save memory? Here is my code:

import { axios } from "@pipedream/platform"

import fs from “fs”;
export default defineComponent({
props: {
docusign: {
type: “app”,
app: “docusign”,
}
},
async run({steps, $}) {
const payload = (await fs.promises.readFile(‘/tmp/docuSignBody.json’))
return await axios($, {
url: https://www.docusign.net//restapi/v2.1/accounts/27620888/envelopes,
headers: {
Authorization: Bearer ${this.docusign.$auth.oauth_access_token},
‘Content-Type’: ‘application/json’
},
data: payload
})
},
})

To handle large payloads efficiently and avoid running out of memory, you can stream the data from the /tmp/ directory using Node.js streams. This approach will help you manage memory usage by not loading the entire file into memory at once. Here’s how you can modify your code to stream the payload: import { axios } from "@pipedream/platform"; import fs from "fs"; export default defineComponent({ props: { docusign: { type: "app", app: "docusign", }, }, async run({ steps, $ }) { const fileStream = fs.createReadStream('/tmp/docuSignBody.json'); return await axios($, { method: "POST", url: `https://www.docusign.net/restapi/v2.1/accounts/27620888/envelopes`, headers: { Authorization: `Bearer ${this.docusign.$auth.oauth_access_token}`, 'Content-Type': 'application/json', }, data: fileStream, }); }, }); ### Key Changes: - Stream the File: Use fs.createReadStream() to create a readable stream from the file. This streams the file content directly to the HTTP request. - Method: Ensure you specify the HTTP method (POST in this case) in the axios configuration. This approach should help you manage large payloads without exhausting memory resources. If you encounter any issues or need further assistance, feel free to ask!

That seems to have worked. Now I get the following error from docusign: AxiosError - Request failed with status code 400

{
  "errorCode": "INVALID_REQUEST_PARAMETER",
  "message": "The request contained at least one invalid parameter. Query parameter 'from_date' must be set to a valid DateTime or 'envelope_ids', 'folder_ids' or 'transaction_ids' must be specified."
}

should I set a from_date as a query param?