mirror of
https://github.com/open-webui/open-webui
synced 2024-11-16 21:42:58 +00:00
Merge pull request #1644 from Entaigner/patch-6
Bugfix: FileReader can't be reused so init one per image
This commit is contained in:
commit
e82d9c873b
@ -316,24 +316,22 @@
|
|||||||
console.log(e);
|
console.log(e);
|
||||||
|
|
||||||
if (e.dataTransfer?.files) {
|
if (e.dataTransfer?.files) {
|
||||||
let reader = new FileReader();
|
|
||||||
|
|
||||||
reader.onload = (event) => {
|
|
||||||
files = [
|
|
||||||
...files,
|
|
||||||
{
|
|
||||||
type: 'image',
|
|
||||||
url: `${event.target.result}`
|
|
||||||
}
|
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
const inputFiles = Array.from(e.dataTransfer?.files);
|
const inputFiles = Array.from(e.dataTransfer?.files);
|
||||||
|
|
||||||
if (inputFiles && inputFiles.length > 0) {
|
if (inputFiles && inputFiles.length > 0) {
|
||||||
inputFiles.forEach((file) => {
|
inputFiles.forEach((file) => {
|
||||||
console.log(file, file.name.split('.').at(-1));
|
console.log(file, file.name.split('.').at(-1));
|
||||||
if (['image/gif', 'image/jpeg', 'image/png'].includes(file['type'])) {
|
if (['image/gif', 'image/jpeg', 'image/png'].includes(file['type'])) {
|
||||||
|
let reader = new FileReader();
|
||||||
|
reader.onload = (event) => {
|
||||||
|
files = [
|
||||||
|
...files,
|
||||||
|
{
|
||||||
|
type: 'image',
|
||||||
|
url: `${event.target.result}`
|
||||||
|
}
|
||||||
|
];
|
||||||
|
};
|
||||||
reader.readAsDataURL(file);
|
reader.readAsDataURL(file);
|
||||||
} else if (
|
} else if (
|
||||||
SUPPORTED_FILE_TYPE.includes(file['type']) ||
|
SUPPORTED_FILE_TYPE.includes(file['type']) ||
|
||||||
@ -470,23 +468,22 @@
|
|||||||
hidden
|
hidden
|
||||||
multiple
|
multiple
|
||||||
on:change={async () => {
|
on:change={async () => {
|
||||||
let reader = new FileReader();
|
|
||||||
reader.onload = (event) => {
|
|
||||||
files = [
|
|
||||||
...files,
|
|
||||||
{
|
|
||||||
type: 'image',
|
|
||||||
url: `${event.target.result}`
|
|
||||||
}
|
|
||||||
];
|
|
||||||
inputFiles = null;
|
|
||||||
filesInputElement.value = '';
|
|
||||||
};
|
|
||||||
|
|
||||||
if (inputFiles && inputFiles.length > 0) {
|
if (inputFiles && inputFiles.length > 0) {
|
||||||
const _inputFiles = Array.from(inputFiles);
|
const _inputFiles = Array.from(inputFiles);
|
||||||
_inputFiles.forEach((file) => {
|
_inputFiles.forEach((file) => {
|
||||||
if (['image/gif', 'image/jpeg', 'image/png'].includes(file['type'])) {
|
if (['image/gif', 'image/jpeg', 'image/png'].includes(file['type'])) {
|
||||||
|
let reader = new FileReader();
|
||||||
|
reader.onload = (event) => {
|
||||||
|
files = [
|
||||||
|
...files,
|
||||||
|
{
|
||||||
|
type: 'image',
|
||||||
|
url: `${event.target.result}`
|
||||||
|
}
|
||||||
|
];
|
||||||
|
inputFiles = null;
|
||||||
|
filesInputElement.value = '';
|
||||||
|
};
|
||||||
reader.readAsDataURL(file);
|
reader.readAsDataURL(file);
|
||||||
} else if (
|
} else if (
|
||||||
SUPPORTED_FILE_TYPE.includes(file['type']) ||
|
SUPPORTED_FILE_TYPE.includes(file['type']) ||
|
||||||
|
Loading…
Reference in New Issue
Block a user