Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
51 changes: 51 additions & 0 deletions file-upload/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
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<Output | void> {
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}'.`);
}
8 changes: 8 additions & 0 deletions file-upload/package.json
Original file line number Diff line number Diff line change
@@ -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
}
Loading