-
Notifications
You must be signed in to change notification settings - Fork 23
/
multipart-form-data.ts
34 lines (31 loc) · 943 Bytes
/
multipart-form-data.ts
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
import { resolveUrl, Uploader } from 'ngx-uploadx';
/**
* Multipart/form-data extended uploader for use with node-uploadx
* @example
* options: UploadxOptions = {
* allowedTypes: 'image/*',
* uploaderClass: MultiPartFormData
* };
*/
export class MultiPartFormData extends Uploader {
async getFileUrl(): Promise<string> {
this.offset = 0;
const formData: FormData = new FormData();
formData.set('metadata', JSON.stringify(this.metadata));
formData.append('file', this.file, this.file.name);
await this.request({
method: 'POST',
body: formData,
url: this.endpoint
});
this.offset = this.size;
const location = this.getValueFromResponse('location');
return location ? resolveUrl(location, this.endpoint) : '';
}
async sendFileContent(): Promise<number | undefined> {
return this.size;
}
async getOffset(): Promise<number | undefined> {
return 0;
}
}