Skip to content

Commit 5b7ca8c

Browse files
committed
Adjusting zoho_desk formdata building
1 parent d8e872a commit 5b7ca8c

File tree

2 files changed

+21
-24
lines changed

2 files changed

+21
-24
lines changed

components/zoho_desk/actions/add-ticket-attachment/add-ticket-attachment.mjs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import zohoDesk from "../../zoho_desk.app.mjs";
2-
import constants from "../../common/constants.mjs";
2+
import { getFileStreamAndMetadata } from "@pipedream/platform";
3+
import FormData from "form-data";
34

45
export default {
56
key: "zoho_desk-add-ticket-attachment",
@@ -44,19 +45,30 @@ export default {
4445
file,
4546
} = this;
4647

48+
const data = new FormData();
49+
const {
50+
stream, metadata,
51+
} = await getFileStreamAndMetadata(file);
52+
data.append("file", stream, {
53+
contentType: metadata.contentType,
54+
knownLength: metadata.size,
55+
filename: metadata.name,
56+
});
57+
4758
const response = await this.zohoDesk.createTicketAttachment({
59+
$,
4860
ticketId,
61+
params: {
62+
isPublic,
63+
},
4964
headers: {
5065
orgId,
51-
...constants.MULTIPART_FORM_DATA_HEADERS,
52-
},
53-
data: {
54-
file,
55-
isPublic,
66+
...data.getHeaders(),
5667
},
68+
data,
5769
});
5870

59-
$.export("$summary", `Successfully created a new ticket attachment with ID ${response.id}`);
71+
$.export("$summary", `Successfully created a new ticket attachment with ID ${response?.id}`);
6072

6173
return response;
6274
},

components/zoho_desk/zoho_desk.app.mjs

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -124,31 +124,16 @@ export default {
124124
$ = this,
125125
url,
126126
path,
127-
headers: preHeaders,
128127
params,
129-
data: preData,
128+
headers,
130129
versionPath = constants.VERSION_PATH,
131130
withRetries = true,
132131
...args
133132
} = {}) {
134-
const contentType = constants.CONTENT_TYPE_KEY_HEADER;
135-
136-
const hasMultipartHeader = utils.hasMultipartHeader(preHeaders);
137-
const data = hasMultipartHeader && await utils.getFormData(preData) || preData;
138-
139-
const currentHeaders = this.getHeaders(preHeaders);
140-
const headers = hasMultipartHeader
141-
? {
142-
...currentHeaders,
143-
[contentType]: data.getHeaders()[contentType.toLowerCase()],
144-
}
145-
: currentHeaders;
146-
147133
const config = {
148-
headers,
149134
url: this.getUrl(url, path, versionPath),
150135
params: this.getParams(url, params),
151-
data,
136+
headers: this.getHeaders(headers),
152137
...args,
153138
};
154139
try {

0 commit comments

Comments
 (0)