From 86a773cffc4517fd1de8ac164c32d6950c331f4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20V=C3=ADcha?= Date: Tue, 14 Apr 2026 16:12:05 +0200 Subject: [PATCH 1/2] added file upload example --- file-upload/index.ts | 53 ++++++++++++++++++++++++++++++++++++++++ file-upload/package.json | 8 ++++++ 2 files changed, 61 insertions(+) create mode 100644 file-upload/index.ts create mode 100644 file-upload/package.json diff --git a/file-upload/index.ts b/file-upload/index.ts new file mode 100644 index 0000000..2f04ba8 --- /dev/null +++ b/file-upload/index.ts @@ -0,0 +1,53 @@ +export function getDescription(): ScriptDescription { + return { + displayName: "File Upload", + description: + "Uploads a file using a specified web endpoint connector. The script will send a POST multipart request to the web endpoint connector.", + category: "Integration", + input: [ + { + id: "connector", + displayName: "Web endpoint connector", + description: + "Must be a web endpoint connector pointing to an API which supports POST multipart requests. You can also append the connector with a relative path.", + type: "Connector", + required: true, + }, + { + id: "file", + displayName: "File", + description: "File to upload.", + type: "InputResource", + required: true, + }, + ], + output: [], + }; +} + +export async function execute(context: Context): Promise { + const connector = context.parameters.connector as string; + const file = context.getFile(context.parameters.file as string); + + console.log(`Starting to upload the '${file.getName()}' file to '${connector}'.`); + + const fileExist = await file.exists(); + if (!fileExist) { + throw new Error("Specified file doesn't exist."); + } + + const formData = new FormData(); + formData.append(file.getName(), file); + + const response = await fetch(connector, { + body: formData, + method: "POST", + }); + + const resultBody = await response.text(); + if (!response.ok) { + throw new Error(`Web endpoint error: HTTP Code ${response.status} - '${resultBody}'.`); + } + console.log("Upload successful."); + console.log(`Web endpoint response: '${resultBody}'.`); +} diff --git a/file-upload/package.json b/file-upload/package.json new file mode 100644 index 0000000..ea507cc --- /dev/null +++ b/file-upload/package.json @@ -0,0 +1,8 @@ +{ + "name": "file-upload", + "displayName": "File upload", + "description": "Uploads file to web endpoint using POST multipart request.", + "fromVersion": "24.10.1.1", + "toVersion": null, + "private": true +} From bb96b356f8cee86cc681af2c6a9e8108023042c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20V=C3=ADcha?= Date: Tue, 14 Apr 2026 16:16:42 +0200 Subject: [PATCH 2/2] formatting --- file-upload/index.ts | 6 ++---- file-upload/package.json | 12 ++++++------ 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/file-upload/index.ts b/file-upload/index.ts index 2f04ba8..f39f108 100644 --- a/file-upload/index.ts +++ b/file-upload/index.ts @@ -1,15 +1,13 @@ export function getDescription(): ScriptDescription { return { displayName: "File Upload", - description: - "Uploads a file using a specified web endpoint connector. The script will send a POST multipart request to the web endpoint connector.", + description: "Uploads a file using a specified web endpoint connector. The script will send a POST multipart request to the web endpoint connector.", category: "Integration", input: [ { id: "connector", displayName: "Web endpoint connector", - description: - "Must be a web endpoint connector pointing to an API which supports POST multipart requests. You can also append the connector with a relative path.", + description: "Must be a web endpoint connector pointing to an API which supports POST multipart requests. You can also append the connector with a relative path.", type: "Connector", required: true, }, diff --git a/file-upload/package.json b/file-upload/package.json index ea507cc..cc9dffa 100644 --- a/file-upload/package.json +++ b/file-upload/package.json @@ -1,8 +1,8 @@ { - "name": "file-upload", - "displayName": "File upload", - "description": "Uploads file to web endpoint using POST multipart request.", - "fromVersion": "24.10.1.1", - "toVersion": null, - "private": true + "name": "file-upload", + "displayName": "File upload", + "description": "Uploads file to web endpoint using POST multipart request.", + "fromVersion": "24.10.1.1", + "toVersion": null, + "private": true }