blob: 4e8dc18c7f729efe1277433396ce745860385f9c [file] [log] [blame]
Michael Landoed64b5e2017-06-09 03:19:04 +03001'use strict';
2
3export interface IUrlToBase64Service {
4 downloadUrl(url:string, callback:Function):void;
5}
6
7export class UrlToBase64Service implements IUrlToBase64Service {
8 constructor() {
9 }
10
11 public downloadUrl = (url:string, callback:Function):void => {
12 let xhr:any = new XMLHttpRequest();
13
14 xhr.onload = ():void => {
15 let reader = new FileReader();
16 reader.onloadend = ():void => {
17 if (xhr.status === 200) {
18 callback(reader.result);
19 } else {
20 callback(null);
21 }
22 };
23 reader.readAsDataURL(xhr.response);
24 };
25 xhr.open('GET', url);
26 xhr.responseType = 'blob';
27 xhr.send();
28 }
29}
30