Skip to content

Applying File URL or Path improvements #16979

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
1aef040
pnpm
GTFalcao Jun 5, 2025
3d6ce07
Updating _2markdown and mapbox
GTFalcao Jun 5, 2025
54a0c8d
Akeneo and LLMWhisperer apps
GTFalcao Jun 5, 2025
49b328f
pnpm
GTFalcao Jun 5, 2025
d174051
add: askyourpdf
GTFalcao Jun 6, 2025
9e11477
add: fileforge
GTFalcao Jun 6, 2025
8a57ff3
adjusting existing descriptions and platform versions
GTFalcao Jun 6, 2025
9bf8aad
Description updates
GTFalcao Jun 6, 2025
c104045
add: microsoft_onedrive, mistral_ai, onlyoffice_docspace
GTFalcao Jun 6, 2025
5624c24
add: slack
GTFalcao Jun 6, 2025
fe3bb7e
add: stannp, zamzar, zoho_desk
GTFalcao Jun 6, 2025
fed67fa
add box upload-file
GTFalcao Jun 6, 2025
b560b05
add: monday, nyckel
GTFalcao Jun 6, 2025
04ae59a
add: ocrspace
GTFalcao Jun 6, 2025
69bbb92
add: onlinecheckwriter, pandadoc, pdf4me
GTFalcao Jun 7, 2025
094bf97
Onedrive adjustment
GTFalcao Jun 9, 2025
0107ed6
pnpm
GTFalcao Jun 9, 2025
8aa2266
adjusting Slack and Pandadoc
GTFalcao Jun 9, 2025
ed11f6e
updates to include metadata in all formdatas
GTFalcao Jun 9, 2025
1afc1fa
pnpm
GTFalcao Jun 9, 2025
c0438fb
fix
GTFalcao Jun 10, 2025
055a2e4
pnpm
GTFalcao Jun 10, 2025
b6a68ad
CodeRabbit fixes
GTFalcao Jun 10, 2025
9158a07
Fixing box and nyckel
GTFalcao Jun 10, 2025
c34250f
fix mapbox
GTFalcao Jun 10, 2025
e89430f
Merge branch 'master' into 16977-applying-fileurl-paths-improvement
GTFalcao Jun 12, 2025
d8e872a
pdf4me: readding std filename check to action
GTFalcao Jun 12, 2025
5b7ca8c
Adjusting zoho_desk formdata building
GTFalcao Jun 13, 2025
86cb294
Merge branch 'master' into 16977-applying-fileurl-paths-improvement
GTFalcao Jun 14, 2025
648cc42
Merge branch 'master' into 16977-applying-fileurl-paths-improvement
GTFalcao Jun 14, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions components/_2markdown/_2markdown.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ export default {
propDefinitions: {
filePath: {
type: "string",
label: "File Path",
description: "The path to an HTML file in the `/tmp` directory. [See the documentation on working with files](https://pipedream.com/docs/code/nodejs/working-with-files/#writing-a-file-to-tmp)",
label: "File Path or URL",
description: "An HTML file. Provide either a file URL or a path to a file in the `/tmp` directory (for example, `/tmp/myFile.html`)",
},
},
methods: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import _2markdown from "../../_2markdown.app.mjs";
import fs from "fs";
import { getFileStreamAndMetadata } from "@pipedream/platform";
import FormData from "form-data";

export default {
key: "_2markdown-html-file-to-markdown",
name: "HTML File to Markdown",
description: "Convert an HTML file to Markdown format. [See the documentation](https://2markdown.com/docs#file2md)",
version: "0.0.1",
version: "0.1.0",
type: "action",
props: {
_2markdown,
Expand All @@ -20,9 +20,14 @@ export default {
async run({ $ }) {
const form = new FormData();

form.append("document", fs.createReadStream(this.filePath.includes("tmp/")
? this.filePath
: `/tmp/${this.filePath}`));
const {
stream, metadata,
} = await getFileStreamAndMetadata(this.filePath);
form.append("document", stream, {
contentType: metadata.contentType,
knownLength: metadata.size,
filename: metadata.name,
});

const response = await this._2markdown.htmlFileToMarkdown({
$,
Expand Down
17 changes: 11 additions & 6 deletions components/_2markdown/actions/pdf-to-markdown/pdf-to-markdown.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import _2markdown from "../../_2markdown.app.mjs";
import fs from "fs";
import { getFileStreamAndMetadata } from "@pipedream/platform";
import FormData from "form-data";

export default {
key: "_2markdown-pdf-to-markdown",
name: "PDF to Markdown",
description: "Convert a PDF document to Markdown format. [See the documentation](https://2markdown.com/docs#pdf2md)",
version: "0.0.1",
version: "0.1.0",
type: "action",
props: {
_2markdown,
Expand All @@ -15,7 +15,7 @@ export default {
_2markdown,
"filePath",
],
description: "The path to a PDF file in the `/tmp` directory. [See the documentation on working with files](https://pipedream.com/docs/code/nodejs/working-with-files/#writing-a-file-to-tmp)",
description: "A PDF file. Provide either a file URL or a path to a file in the `/tmp` directory (for example, `/tmp/myFile.pdf`)",
},
waitForCompletion: {
type: "boolean",
Expand All @@ -27,9 +27,14 @@ export default {
async run({ $ }) {
const form = new FormData();

form.append("document", fs.createReadStream(this.filePath.includes("tmp/")
? this.filePath
: `/tmp/${this.filePath}`));
const {
stream, metadata,
} = await getFileStreamAndMetadata(this.filePath);
form.append("document", stream, {
contentType: metadata.contentType,
knownLength: metadata.size,
filename: metadata.name,
});

let response = await this._2markdown.pdfToMarkdown({
$,
Expand Down
4 changes: 2 additions & 2 deletions components/_2markdown/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/_2markdown",
"version": "0.1.0",
"version": "0.2.0",
"description": "Pipedream 2markdown Components",
"main": "_2markdown.app.mjs",
"keywords": [
Expand All @@ -13,7 +13,7 @@
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.0.3",
"@pipedream/platform": "^3.1.0",
"form-data": "^4.0.1"
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import app from "../../akeneo.app.mjs";
import utils from "../../common/utils.mjs";
import { ConfigurationError } from "@pipedream/platform";
import {
ConfigurationError, getFileStreamAndMetadata,
} from "@pipedream/platform";
import FormData from "form-data";
import fs from "fs";

export default {
type: "action",
key: "akeneo-create-a-new-product-media-file",
version: "0.0.1",
version: "0.1.0",
name: "Create A New Product Media File",
description: "Allows you to create a new media file and associate it to an attribute value of a given product or product model. [See the docs](https://api.akeneo.com/api-reference.html#post_media_files)",
props: {
Expand All @@ -32,18 +32,15 @@ export default {
},
filename: {
type: "string",
label: "File",
description: "The file to be uploaded, please provide a file from `/tmp`. To upload a file to `/tmp` folder, please follow the doc [here](https://pipedream.com/docs/code/nodejs/working-with-files/#writing-a-file-to-tmp)",
label: "File Path or URL",
description: "The file to be uploaded. Provide either a file URL or a path to a file in the `/tmp` directory (for example, `/tmp/myFile.txt`)",
},
},
async run ({ $ }) {
if (!this.productId && !this.productModelCode) {
throw new ConfigurationError("Either `Product Identifier` or `Product Model Code` should be set!");
}
const path = utils.checkTmp(this.filename);
if (!fs.existsSync(path)) {
throw new ConfigurationError("File does not exist!");
}

const payload = {
attribute: this.mediaFileAttributeCode,
scope: null,
Expand All @@ -57,9 +54,15 @@ export default {
payload.code = this.productModelCode;
data.append("product_model", JSON.stringify(payload));
}
const file = fs.readFileSync(path);
const fileParts = path.split("/");
data.append("file", file, fileParts[fileParts.length - 1]);

const {
stream, metadata,
} = await getFileStreamAndMetadata(this.filename);
data.append("file", stream, {
contentType: metadata.contentType,
knownLength: metadata.size,
filename: metadata.name,
});
const contentLength = data.getLengthSync();
await this.app.createProductMediaFile({
$,
Expand Down
4 changes: 2 additions & 2 deletions components/akeneo/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/akeneo",
"version": "0.0.2",
"version": "0.1.0",
"description": "Pipedream Akeneo Components",
"main": "akeneo.app.mjs",
"keywords": [
Expand All @@ -10,7 +10,7 @@
"homepage": "https://pipedream.com/apps/akeneo",
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"dependencies": {
"@pipedream/platform": "^1.3.0",
"@pipedream/platform": "^3.1.0",
"form-data": "^4.0.0"
},
"publishConfig": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ export default {
name: "Add Document Via File Upload",
description: "Add a document via file upload. [See the documentation](https://docs.askyourpdf.com/askyourpdf-docs/#2.-adding-document-via-file-upload)",
type: "action",
version: "0.0.2",
version: "0.1.0",
props: {
app,
file: {
type: "string",
label: "File Path",
description: "File path of a file previously downloaded in Pipedream E.g. (`/tmp/my-file.txt`). [Download a file to the `/tmp` directory](https://pipedream.com/docs/code/nodejs/http-requests/#download-a-file-to-the-tmp-directory)",
label: "File Path or URL",
description: "The file to upload. Provide either a file URL or a path to a file in the `/tmp` directory (for example, `/tmp/myFile.txt`)",
},
},
methods: {
Expand Down
6 changes: 3 additions & 3 deletions components/askyourpdf/askyourpdf.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ export default {
...headers,
};
},
getConfig({
async getConfig({
headers, data: preData, ...args
} = {}) {
const contentType = constants.CONTENT_TYPE_KEY_HEADER;
const hasMultipartHeader = utils.hasMultipartHeader(headers);
const data = hasMultipartHeader && utils.getFormData(preData) || preData;
const data = hasMultipartHeader && await utils.getFormData(preData) || preData;
const currentHeaders = this.getHeaders(headers);

return {
Expand All @@ -49,7 +49,7 @@ export default {
async makeRequest({
step = this, path, headers, data, summary, ...args
} = {}) {
const config = this.getConfig({
const config = await this.getConfig({
url: this.getUrl(path),
headers,
data,
Expand Down
26 changes: 15 additions & 11 deletions components/askyourpdf/common/utils.mjs
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
import { createReadStream } from "fs";
import { getFileStreamAndMetadata } from "@pipedream/platform";
import FormData from "form-data";
import constants from "./constants.mjs";

function buildFormData(formData, data, parentKey) {
async function buildFormData(formData, data, parentKey) {
if (data && typeof(data) === "object") {
Object.keys(data)
.forEach(async (key) => {
buildFormData(formData, data[key], parentKey && `${parentKey}[${key}]` || key);
});

for (const key of Object.keys(data)) {
await buildFormData(formData, data[key], parentKey && `${parentKey}[${key}]` || key);
}
} else if (data && constants.FILE_PROP_NAMES.some((prop) => parentKey.includes(prop))) {
formData.append(parentKey, createReadStream(data));

const {
stream, metadata,
} = await getFileStreamAndMetadata(data);
formData.append(parentKey, stream, {
contentType: metadata.contentType,
knownLength: metadata.size,
filename: metadata.name,
});
} else if (data) {
formData.append(parentKey, (data).toString());
}
}

function getFormData(data) {
async function getFormData(data) {
try {
const formData = new FormData();
buildFormData(formData, data);
await buildFormData(formData, data);
return formData;
} catch (error) {
console.log("FormData Error", error);
Expand Down
7 changes: 3 additions & 4 deletions components/askyourpdf/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/askyourpdf",
"version": "0.1.1",
"version": "0.2.0",
"description": "Pipedream AskYourPDF Components",
"main": "askyourpdf.app.mjs",
"keywords": [
Expand All @@ -10,9 +10,8 @@
"homepage": "https://pipedream.com/apps/askyourpdf",
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"dependencies": {
"@pipedream/platform": "^1.6.2",
"form-data": "^4.0.0",
"fs": "^0.0.1-security"
"@pipedream/platform": "^3.1.0",
"form-data": "^4.0.0"
},
"publishConfig": {
"access": "public"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default {
name: "Upload File Version",
description: "Update a file's content. [See the documentation](https://developer.box.com/reference/post-files-id-content/).",
key: "box-upload-file-version",
version: "0.0.2",
version: "0.1.0",
type: "action",
props: {
app,
Expand Down Expand Up @@ -55,7 +55,7 @@ export default {
const {
file, fileId, createdAt, modifiedAt, fileName, parentId,
} = this;
const data = this.getFileUploadBody({
const data = await this.getFileUploadBody({
file,
createdAt,
modifiedAt,
Expand Down
4 changes: 2 additions & 2 deletions components/box/actions/upload-file/upload-file.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default {
name: "Upload a File",
description: "Uploads a small file to Box. [See the documentation](https://developer.box.com/reference/post-files-content/).",
key: "box-upload-file",
version: "0.0.4",
version: "0.1.0",
type: "action",
props: {
app,
Expand Down Expand Up @@ -47,7 +47,7 @@ export default {
const {
file, createdAt, modifiedAt, fileName, parentId,
} = this;
const data = this.getFileUploadBody({
const data = await this.getFileUploadBody({
file,
createdAt,
modifiedAt,
Expand Down
4 changes: 2 additions & 2 deletions components/box/box.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export default {
},
file: {
type: "string",
label: "File",
description: "The file to upload to Box, please provide a file from `/tmp`. To upload a file to `/tmp` folder, please follow the doc [here](https://pipedream.com/docs/code/nodejs/working-with-files/#writing-a-file-to-tmp)",
label: "File Path or URL",
description: "The file to upload. Provide either a file URL or a path to a file in the `/tmp` directory (for example, `/tmp/myFile.txt`)",
},
createdAt: {
type: "string",
Expand Down
12 changes: 4 additions & 8 deletions components/box/common/common-file-upload.mjs
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
import { ConfigurationError } from "@pipedream/platform";
import FormData from "form-data";
import utils from "./utils.mjs";

export function getFileUploadBody({
export async function getFileUploadBody({
file,
createdAt,
modifiedAt,
fileName,
parentId,
}) {
const fileValidation = utils.isValidFile(file);
if (!fileValidation) {
throw new ConfigurationError("`file` must be a valid file path!");
}
const fileMeta = utils.getFileMeta(fileValidation);
const fileContent = utils.getFileStream(fileValidation);
const {
fileMeta, fileContent,
} = await utils.getFileData(file);
const attributes = fileMeta.attributes;
if (createdAt && utils.checkRFC3339(createdAt)) {
attributes.content_created_at = createdAt;
Expand Down
Loading
Loading