Skip to content

Commit

Permalink
feat: support multipart/form-data requests in Use FME Service activity (
Browse files Browse the repository at this point in the history
  • Loading branch information
rcooney authored Jun 21, 2022
1 parent 78ed739 commit d15f254
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/activities/UseFmeService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface UseFmeServiceInputs {
| "notifications/topics"
| "repositories"
| "resources/connections"
| "resources/types"
| "schedules"
| "schedules/categories"
| string;
Expand All @@ -35,7 +36,10 @@ export interface UseFmeServiceInputs {
/**
* @description The content type of the request. This is required when the method is POST or PUT.
*/
contentType?: "application/x-www-form-urlencoded" | "application/json";
contentType?:
| "application/x-www-form-urlencoded"
| "application/json"
| "multipart/form-data";
/**
* @description The body parameters to pass to the service operation when the method is POST or PUT.
*/
Expand Down Expand Up @@ -68,15 +72,21 @@ export class UseFmeService implements IActivityHandler {
throw new Error("path is required");
}

let body: string | undefined;
let params: string | FormData | undefined;
if (typeof parameters === "object") {
if (contentType === "application/json") {
body = JSON.stringify(parameters);
params = JSON.stringify(parameters);
} else if (contentType === "application/x-www-form-urlencoded") {
body = objectToQueryString(parameters);
params = objectToQueryString(parameters);
} else if (contentType === "multipart/form-data") {
const formData = new FormData();
for (const name in parameters) {
formData.append(name, parameters[name]);
}
params = formData;
}
} else {
body = parameters;
params = parameters;
}

/* eslint-disable @typescript-eslint/no-non-null-assertion */
Expand All @@ -89,7 +99,7 @@ export class UseFmeService implements IActivityHandler {
result,
});
},
body!,
params as any, // FormData is accepted and used internally by the API.
contentType!
);
});
Expand Down

0 comments on commit d15f254

Please sign in to comment.