mirror of
https://github.com/frappe/books.git
synced 2024-11-10 15:50:56 +00:00
fix: Save image as base64 in database
This commit is contained in:
parent
a988124f64
commit
4ea71aca1a
@ -7,7 +7,10 @@
|
|||||||
@click="openFileSelector"
|
@click="openFileSelector"
|
||||||
>
|
>
|
||||||
<template v-if="!value">
|
<template v-if="!value">
|
||||||
<div v-if="letterPlaceholder" class="bg-gray-500 flex h-full items-center justify-center text-white w-full text-4xl">
|
<div
|
||||||
|
v-if="letterPlaceholder"
|
||||||
|
class="bg-gray-500 flex h-full items-center justify-center text-white w-full text-4xl"
|
||||||
|
>
|
||||||
{{ letterPlaceholder }}
|
{{ letterPlaceholder }}
|
||||||
</div>
|
</div>
|
||||||
<svg
|
<svg
|
||||||
@ -37,6 +40,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import frappe from 'frappejs';
|
||||||
import { remote } from 'electron';
|
import { remote } from 'electron';
|
||||||
import Base from './Base';
|
import Base from './Base';
|
||||||
|
|
||||||
@ -57,15 +61,30 @@ export default {
|
|||||||
title: frappe._('Select Image'),
|
title: frappe._('Select Image'),
|
||||||
properties: ['openFile'],
|
properties: ['openFile'],
|
||||||
filters: [
|
filters: [
|
||||||
{ name: 'Image', extensions: ['png', 'jpg', 'svg', 'jpeg', 'webp'] }
|
{ name: 'Image', extensions: ['png', 'jpg', 'jpeg', 'webp'] }
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
files => {
|
async files => {
|
||||||
if (files && files[0]) {
|
if (files && files[0]) {
|
||||||
this.triggerChange(`file://${files[0]}`);
|
let dataURL = await this.getDataURL(files[0]);
|
||||||
|
this.triggerChange(dataURL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
},
|
||||||
|
getDataURL(filePath) {
|
||||||
|
let fs = require('fs');
|
||||||
|
let path = require('path');
|
||||||
|
let typedArray = fs.readFileSync(filePath);
|
||||||
|
let extension = path.extname(filePath).slice(1);
|
||||||
|
let blob = new Blob([typedArray.buffer], { type: 'image/' + extension });
|
||||||
|
return new Promise(resolve => {
|
||||||
|
let fr = new FileReader();
|
||||||
|
fr.addEventListener('loadend', () => {
|
||||||
|
resolve(fr.result);
|
||||||
|
});
|
||||||
|
fr.readAsDataURL(blob);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user