-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
37 lines (29 loc) · 870 Bytes
/
index.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
35
36
37
class FileToBlobUrl {
private VM: null|HTMLInputElement;
constructor({ type }: Pick<HTMLInputElement, 'type'>) {
this.VM = null;
this.createVM();
this.setContributes({ type, onchange });
this.autoTrigger();
}
createVM() {
this.VM = document.createElement("input");
}
setContributes(attrs: Partial<HTMLInputElement>) {
const { type, onchange } = attrs || {};
this.VM.type = type;
this.VM.onchange = onchange;
}
autoTrigger() {
this.VM?.click();
}
onChange(e: Event) {
const data = (<HTMLInputElement>e.target).files[0];
const reader = new FileReader();
reader.readAsDataURL(data);
reader.onload = function (e) {
// URL.createObjectURL(e.target.result )
return e.target.result;
}
}
}