Worker and Google Ai FileManager Problem

Hi everyone! I'm trying to use the File API with Gemini in a Cloudflare Worker environment, but I'm running into an issue. According to the documentation, we can use the File API to handle files up to 2GB (instead of the 20MB limit with inline data). However, the GoogleAIFileManager.uploadFile() method seems to only accept a file path string and uses fs.readFileSync internally, which isn't available in Cloudflare Workers. Is there any way to use the File API with an ArrayBuffer or a URL directly? My use case is: 1. User uploads file to our R2 storage 2. I get the file as ArrayBuffer in our Worker 3. I want to send this to Gemini for analysis without the 20MB limit Currently, im forced to use the inline data approach with the 20MB limit since we can't use fs in Workers. Any suggestions for handling larger files in serverless environments?
1 Reply
ajgeiss0702
ajgeiss07026d ago
you might need to make your own wrapper for google's api. Info for doing that can be found in the Shell section: https://ai.google.dev/api/files#files_create_image-SHELL

Did you find this page helpful?