mirror of
https://github.com/open-webui/open-webui
synced 2025-06-26 18:26:48 +00:00
Feature: adjusted file upload to handle individual rag config (send knowledge base id to get rag config)
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
import { WEBUI_API_BASE_URL } from '$lib/constants';
|
||||
|
||||
export const uploadFile = async (token: string, file: File) => {
|
||||
export const uploadFile = async (token: string, file: File, knowledge_id: string) => {
|
||||
const data = new FormData();
|
||||
data.append('file', file);
|
||||
data.append('knowledge_id', knowledge_id);
|
||||
let error = null;
|
||||
|
||||
const res = await fetch(`${WEBUI_API_BASE_URL}/files/`, {
|
||||
|
||||
@@ -118,7 +118,7 @@
|
||||
return file;
|
||||
};
|
||||
|
||||
const uploadFileHandler = async (file) => {
|
||||
const uploadFileHandler = async (file, knowledgeId) => {
|
||||
console.log(file);
|
||||
|
||||
const tempItemId = uuidv4();
|
||||
@@ -158,7 +158,7 @@
|
||||
knowledge.files = [...(knowledge.files ?? []), fileItem];
|
||||
|
||||
try {
|
||||
const uploadedFile = await uploadFile(localStorage.token, file).catch((e) => {
|
||||
const uploadedFile = await uploadFile(localStorage.token, file, knowledgeId).catch((e) => {
|
||||
toast.error(`${e}`);
|
||||
return null;
|
||||
});
|
||||
@@ -249,7 +249,7 @@
|
||||
const file = await entry.getFile();
|
||||
const fileWithPath = new File([file], entryPath, { type: file.type });
|
||||
|
||||
await uploadFileHandler(fileWithPath);
|
||||
await uploadFileHandler(fileWithPath, id);
|
||||
uploadedFiles++;
|
||||
updateProgress();
|
||||
} else if (entry.kind === 'directory') {
|
||||
@@ -311,7 +311,7 @@
|
||||
const relativePath = file.webkitRelativePath || file.name;
|
||||
const fileWithPath = new File([file], relativePath, { type: file.type });
|
||||
|
||||
await uploadFileHandler(fileWithPath);
|
||||
await uploadFileHandler(fileWithPath, id);
|
||||
uploadedFiles++;
|
||||
updateProgress();
|
||||
}
|
||||
@@ -509,7 +509,7 @@
|
||||
|
||||
if (inputFiles && inputFiles.length > 0) {
|
||||
for (const file of inputFiles) {
|
||||
await uploadFileHandler(file);
|
||||
await uploadFileHandler(file, id);
|
||||
}
|
||||
} else {
|
||||
toast.error($i18n.t(`File not found.`));
|
||||
@@ -628,7 +628,7 @@
|
||||
bind:show={showAddTextContentModal}
|
||||
on:submit={(e) => {
|
||||
const file = createFileFromText(e.detail.name, e.detail.content);
|
||||
uploadFileHandler(file);
|
||||
uploadFileHandler(file, id);
|
||||
}}
|
||||
/>
|
||||
|
||||
@@ -641,7 +641,7 @@
|
||||
on:change={async () => {
|
||||
if (inputFiles && inputFiles.length > 0) {
|
||||
for (const file of inputFiles) {
|
||||
await uploadFileHandler(file);
|
||||
await uploadFileHandler(file, id);
|
||||
}
|
||||
|
||||
inputFiles = null;
|
||||
|
||||
Reference in New Issue
Block a user