-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuildAttachment.ts
More file actions
44 lines (39 loc) · 1.17 KB
/
buildAttachment.ts
File metadata and controls
44 lines (39 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import Axios from "axios";
import {AttachmentBuilder} from "../../api/common";
import {APIOptions, Callback} from "../../model/models";
class AttachmentBuilderImpl implements AttachmentBuilder {
private apiOptions: APIOptions;
private attachment: File | Blob;
constructor(apiOptions: APIOptions, attachment: File | Blob) {
this.apiOptions = apiOptions;
this.attachment = attachment;
}
public ok(callback?: Callback<string[]>): void {
const data: FormData = new FormData();
data.append("attachment", this.attachment);
const url = `${this.apiOptions.server}/attachment`;
const header: { [key: string]: string } = {};
for (const k in this.apiOptions.headers) {
if (k.toLowerCase() !== "content-type") {
header[k] = this.apiOptions.headers[k];
}
}
Axios.post(url, data, {headers: header})
.then((response) => {
return response.data as string[];
})
.then((result) => {
if (callback) {
callback(null, result);
}
})
.catch((e) => {
if (callback) {
callback(e);
}
});
}
}
export {
AttachmentBuilderImpl,
};