From 5d7311cf7247a69b5be418713bc64d12849963cb Mon Sep 17 00:00:00 2001 From: randolf joshua diezmo Date: Fri, 7 Dec 2018 22:32:13 +0800 Subject: [PATCH 1/2] Fix upload json parse file --- src/components/FileEditor/FileEditor.react.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/components/FileEditor/FileEditor.react.js b/src/components/FileEditor/FileEditor.react.js index 794b79affd..664dfd296a 100644 --- a/src/components/FileEditor/FileEditor.react.js +++ b/src/components/FileEditor/FileEditor.react.js @@ -44,10 +44,20 @@ export default class FileEditor extends React.Component { } } - handleChange(e) { + getBase64(file){ + return new Promise((resolve, reject) => { + const reader = new FileReader(); + reader.readAsDataURL(file); + reader.onload = () => resolve(reader.result); + reader.onerror = error => reject(error); + }); + } + + async handleChange(e) { let file = e.target.files[0]; if (file) { - this.props.onCommit(new Parse.File(file.name, file)); + let base64 = await this.getBase64(file); + this.props.onCommit(new Parse.File(file.name, {base64})); } } From c88d90c325492bb132681fa40c55a334a05fc28e Mon Sep 17 00:00:00 2001 From: randolf joshua diezmo Date: Mon, 10 Dec 2018 12:08:18 +0800 Subject: [PATCH 2/2] add spaces between base64 --- src/components/FileEditor/FileEditor.react.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/FileEditor/FileEditor.react.js b/src/components/FileEditor/FileEditor.react.js index 664dfd296a..a3c06cafe9 100644 --- a/src/components/FileEditor/FileEditor.react.js +++ b/src/components/FileEditor/FileEditor.react.js @@ -57,7 +57,7 @@ export default class FileEditor extends React.Component { let file = e.target.files[0]; if (file) { let base64 = await this.getBase64(file); - this.props.onCommit(new Parse.File(file.name, {base64})); + this.props.onCommit(new Parse.File(file.name, { base64 })); } }