Hello, I’m trying utilize Gemini’s File search API in Tauri Application with below code.
// <TAURIPROJECT>/src/main.js
async function handleFileUpload(event) {
const ai = new GoogleGenAI({
apiKey: "YOUR_API_KEY", // Replace with your actual API key
});
const button = event.target;
const storeName = button.getAttribute("data-store-name");
try {
const filePath = await open({ // from "@tauri-apps/plugin-dialog";
multiple: false,
directory: false,
});
const fileData = await readFile(filePath); // from "@tauri-apps/plugin-fs";
const fileBlob = new Blob([fileData]);
const filePath_print = filePath.split("/").pop();
let operation = await ai.fileSearchStores.uploadToFileSearchStore({
file: fileBlob,
fileSearchStoreName: storeName,
config: {
displayName: filePath_print, // THIS NOT WORKING EVEN WITH SOME FIXED STRING
},
});
while (!operation.done) {
await new Promise((resolve) => setTimeout(resolve, 5000));
operation = await ai.operations.get({ operation });
}
}
}
I used file selector of Tauri application, and get file’s path and read it as Blob object; since browser of tauri didn’t support file path directly ([Error] File path is not supported in browser uploader)
[RESULT] It seems working well, but the displayName in config didn’t work properly, below is console.log of documents.list of fileSearchStores API:
const documents = await ai.fileSearchStores.documents.list({
parent: store.name,
});
Object
createTime: "..."
mimeType: "application/pdf"
name: "fileSearchStores/SOMEPATH"
sizeBytes: "8697299"
state: "STATE_ACTIVE"
updateTime: "..."
[EXPECTED] Which worked fine in just running js code with node command.
Object
createTime: “...”
displayName: “note.pdf”
mimeType: “application/pdf”
name: “fileSearchStores/SOMEPATH”
sizeBytes: “8697299”
state: “STATE_ACTIVE”
updateTime: “…”
The different point from example code is 2 thing.
1: I used fileblob not filepath
2: I used npm run tauri dev instead of node main.js
Do you have any idea to solve this problem?
Thanks