mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-25 18:02:23 +01:00
support binary files in the file widget
This commit is contained in:
parent
ff636102ba
commit
28ff90b8bf
1 changed files with 11 additions and 3 deletions
|
|
@ -6,6 +6,11 @@ export interface LocalFile {
|
|||
content: string;
|
||||
}
|
||||
|
||||
export function getBase64FromDataUrl(dataUrl: string): string {
|
||||
const commaIndex = dataUrl.indexOf(',');
|
||||
return dataUrl.substring(commaIndex + 1, dataUrl.length);
|
||||
}
|
||||
|
||||
export default class FileControl extends React.Component<any> {
|
||||
|
||||
render() {
|
||||
|
|
@ -19,12 +24,15 @@ export default class FileControl extends React.Component<any> {
|
|||
|
||||
const file = files[0];
|
||||
|
||||
file.text().then(content => {
|
||||
const reader = new FileReader();
|
||||
reader.onload = evt => {
|
||||
const dataUrl = evt.target.result as string;
|
||||
onChange({
|
||||
fileName: name,
|
||||
content
|
||||
content: dataUrl
|
||||
})
|
||||
});
|
||||
};
|
||||
reader.readAsDataURL(file);
|
||||
}
|
||||
|
||||
return <div className={type}>
|
||||
|
|
|
|||
Loading…
Reference in a new issue