Preparing for github file persistence

This commit is contained in:
Cássio Zen
2016-07-19 17:11:22 -03:00
parent 6f0f13ad40
commit 18ad041d96
13 changed files with 181 additions and 44 deletions

View File

@ -7,8 +7,21 @@ export default function MediaProxy(value, file, uploaded = false) {
this.value = value;
this.file = file;
this.uploaded = uploaded;
this.uri = config.media_folder && !uploaded ? config.media_folder + '/' + value : value;
this.toString = function() {
return this.uploaded ? this.uri : window.URL.createObjectURL(this.file, { oneTimeOnly: true });
};
this.sha = null;
this.path = config.media_folder && !uploaded ? config.media_folder + '/' + value : value;
}
MediaProxy.prototype.toString = function() {
return this.uploaded ? this.path : window.URL.createObjectURL(this.file, { oneTimeOnly: true });
};
MediaProxy.prototype.toBase64 = function() {
return new Promise((resolve, reject) => {
const fr = new FileReader();
fr.onload = (readerEvt) => {
const binaryString = readerEvt.target.result;
resolve(btoa(binaryString));
};
fr.readAsDataURL(this.file);
});
};