[SDC-29] catalog 1707 rebase commit.
Change-Id: I43c3dc5cf44abf5da817649bc738938a3e8388c1
Signed-off-by: Michael Lando <ml636r@att.com>
diff --git a/catalog-ui/src/app/services/url-tobase64-service.ts b/catalog-ui/src/app/services/url-tobase64-service.ts
new file mode 100644
index 0000000..4e8dc18
--- /dev/null
+++ b/catalog-ui/src/app/services/url-tobase64-service.ts
@@ -0,0 +1,30 @@
+'use strict';
+
+export interface IUrlToBase64Service {
+ downloadUrl(url:string, callback:Function):void;
+}
+
+export class UrlToBase64Service implements IUrlToBase64Service {
+ constructor() {
+ }
+
+ public downloadUrl = (url:string, callback:Function):void => {
+ let xhr:any = new XMLHttpRequest();
+
+ xhr.onload = ():void => {
+ let reader = new FileReader();
+ reader.onloadend = ():void => {
+ if (xhr.status === 200) {
+ callback(reader.result);
+ } else {
+ callback(null);
+ }
+ };
+ reader.readAsDataURL(xhr.response);
+ };
+ xhr.open('GET', url);
+ xhr.responseType = 'blob';
+ xhr.send();
+ }
+}
+