Editor.js: Upload images and attach as base64

Created on 5 Aug 2019  路  2Comments  路  Source: codex-team/editor.js

Hey Guys I have a requirement to upload the images as base64. So instead of passing the images to an end point url they will be embedded as base64. Can someone pass me in the right direction

Thanks

Most helpful comment

you can try

uploadByFile(file){
return _getBase64(file, function(e) {}).then((data)=>{
return {
success: 1,
file: {
url: data
}
}
})
}

declare function
function _getBase64(file, onLoadCallback) {
return new Promise(function(resolve, reject) {
var reader = new FileReader();
reader.onload = function() { return resolve(reader.result ); };
reader.onerror = reject;
reader.readAsDataURL(file);
});
}

All 2 comments

For anyone else that's looking you can use this method on upload

https://github.com/editor-js/image#server-format

you can try

uploadByFile(file){
return _getBase64(file, function(e) {}).then((data)=>{
return {
success: 1,
file: {
url: data
}
}
})
}

declare function
function _getBase64(file, onLoadCallback) {
return new Promise(function(resolve, reject) {
var reader = new FileReader();
reader.onload = function() { return resolve(reader.result ); };
reader.onerror = reject;
reader.readAsDataURL(file);
});
}

Was this page helpful?
0 / 5 - 0 ratings

Related issues

davedbase picture davedbase  路  3Comments

sei-jdshimkoski picture sei-jdshimkoski  路  5Comments

Yakumo-Yukari picture Yakumo-Yukari  路  5Comments

hata6502 picture hata6502  路  3Comments

oknoorap picture oknoorap  路  4Comments