Skip to content

Commit d15f254

Browse files
authored
feat: support multipart/form-data requests in Use FME Service activity (#30)
1 parent 78ed739 commit d15f254

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

src/activities/UseFmeService.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export interface UseFmeServiceInputs {
2525
| "notifications/topics"
2626
| "repositories"
2727
| "resources/connections"
28+
| "resources/types"
2829
| "schedules"
2930
| "schedules/categories"
3031
| string;
@@ -35,7 +36,10 @@ export interface UseFmeServiceInputs {
3536
/**
3637
* @description The content type of the request. This is required when the method is POST or PUT.
3738
*/
38-
contentType?: "application/x-www-form-urlencoded" | "application/json";
39+
contentType?:
40+
| "application/x-www-form-urlencoded"
41+
| "application/json"
42+
| "multipart/form-data";
3943
/**
4044
* @description The body parameters to pass to the service operation when the method is POST or PUT.
4145
*/
@@ -68,15 +72,21 @@ export class UseFmeService implements IActivityHandler {
6872
throw new Error("path is required");
6973
}
7074

71-
let body: string | undefined;
75+
let params: string | FormData | undefined;
7276
if (typeof parameters === "object") {
7377
if (contentType === "application/json") {
74-
body = JSON.stringify(parameters);
78+
params = JSON.stringify(parameters);
7579
} else if (contentType === "application/x-www-form-urlencoded") {
76-
body = objectToQueryString(parameters);
80+
params = objectToQueryString(parameters);
81+
} else if (contentType === "multipart/form-data") {
82+
const formData = new FormData();
83+
for (const name in parameters) {
84+
formData.append(name, parameters[name]);
85+
}
86+
params = formData;
7787
}
7888
} else {
79-
body = parameters;
89+
params = parameters;
8090
}
8191

8292
/* eslint-disable @typescript-eslint/no-non-null-assertion */
@@ -89,7 +99,7 @@ export class UseFmeService implements IActivityHandler {
8999
result,
90100
});
91101
},
92-
body!,
102+
params as any, // FormData is accepted and used internally by the API.
93103
contentType!
94104
);
95105
});

0 commit comments

Comments
 (0)