Im trying to use @google/generative-ai
in Javascript with in-memory images. My server gets the images from Http Requests. In google documentation it shows that:
// TODO Make these files available on the local file system
// You may need to update the file paths
const files = [
await uploadToGemini("file_path", "image/jpeg"),
];
async function uploadToGemini(path, mimeType) {
const uploadResult = await fileManager.uploadFile(path, {
mimeType,
displayName: path,
});
const file = uploadResult.file;
console.log(`Uploaded file ${file.displayName} as: ${file.name}`);
return file;
}
const fileManager = new GoogleAIFileManager(apiKey);
So it expects a file path. So now I need to
- Save the image to a local folder
- Read the image from local folder and upload it to google servers
- Delete the image from local folder
It seems unnecessary. The image is being sent in base64 format anyway, why should I save it to the local file instead of directly sending the image from memory. As far as documentation goes, I couldn’t find a way to achieve that. Is there a workaround for this?
I looked at the source code of GoogleAIFileManager
it only accepts filePath as parameter.