Skip to content

Commit

Permalink
Fix a issue in posting with a image (implement FileUtil.exists())
Browse files Browse the repository at this point in the history
  • Loading branch information
toshiakisp committed Sep 11, 2018
1 parent b11ea48 commit 6942bbe
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion akahuku/content/fileutil.js
Expand Up @@ -70,7 +70,25 @@ AkahukuFileUtil.getLastModified = function (file) {
* @return Promise for File that exists (readable)
*/
AkahukuFileUtil.exists = async function (file) {
return new Promise.reject(new Error('NotImplemented'));
return new Promise((resolve, reject) => {
let reader =new FileReader();
let determined = false;
reader.onprogress = (event) => {
if (event.loaded > 0) { // exists (readable)
determined = true;
resolve(file);
reader.abort();
}
};
reader.onabort = (event) => {
if (!determined)
reject(new Error('Aborted reading a file'));
};
reader.onerror = (event) => {
reject(new Error('Error occurs in reading a file'));
};
reader.readAsArrayBuffer(file);
});
};


Expand Down

0 comments on commit 6942bbe

Please sign in to comment.