AnimationTool/app/file_handler.ts

32 lines
738 B
TypeScript
Raw Normal View History

2019-09-25 03:16:07 +00:00
export class FileHandler {
2019-09-26 01:59:16 +00:00
public static ProcessImages = (fileList: FileList): Promise<string[]> => {
return new Promise(async (resolve, reject) => {
const filenames: string[] = [];
2019-09-25 03:16:07 +00:00
2019-09-26 01:59:16 +00:00
for (let i = 0; i < fileList.length; i++) {
const file = fileList[i];
const filename = await FileHandler.ProcessImage(file);
filenames.push(filename);
}
resolve(filenames);
});
};
private static ProcessImage = (file: File): Promise<string> => {
return new Promise((resolve, reject) => {
2019-09-25 03:16:07 +00:00
const reader = new FileReader();
2019-09-26 01:59:16 +00:00
reader.onload = (event: any) => {
resolve(event.target!.result);
};
2019-09-25 03:16:07 +00:00
2019-09-26 01:59:16 +00:00
reader.onerror = reject;
2019-09-25 03:16:07 +00:00
2019-09-26 01:59:16 +00:00
// Read in the image file as a data URL.
reader.readAsDataURL(file);
});
};
2019-09-25 03:16:07 +00:00
}