GeminiWithFiles
This is a Google Apps Script library for Gemini API with files.
AI Summary
GeminiWithFiles
A Google Apps Script wrapper that uploads files to the Gemini API and handles generative-AI interactions
Target Users
Intermediate-to-advanced GAS developers who need to analyse or generate content from Drive-stored images, PDFs, etc. via the Gemini API
Problems Solved
Passing files from GAS to Gemini requires handling MIME conversion, 50 MB limits and async uploads, which is cumbersome to implement manually
Tags
Main Features
One-liner upload of Drive files
Simply pass file IDs or Blobs to upload images, PDFs or videos asynchronously; resumable upload handles files larger than 50 MB
Batch generation & multimodal support
Feed Gemini up to thousands of images or many files at once and obtain descriptions, summaries, etc. in a single API call
Output controlled via JSON schema
Specify response_mime_type and schema to receive strictly formatted JSON, simplifying downstream processing
Chat, token counting & utilities
Provides chat history, token counting, function calling and system instructions as straightforward helper methods
Usage Examples
Upload one image and get a description
function quickDemo() {
const apiKey = 'YOUR_API_KEY'; // Acquire from MakerSuite
const fileId = 'DRIVE_FILE_ID'; // Image to describe
// When the library is installed
const g = GeminiWithFiles.geminiWithFiles({ apiKey });
// Upload the image
const files = g.setFileIds([fileId]).uploadFiles();
// Ask Gemini for a caption
const res = g.withUploadedFilesByGenerateContent(files)
.generateContent({ q: 'Describe this image in under 50 words.' });
Logger.log(res); // => Generated caption
}
This minimal snippet uploads a Drive image and asks Gemini for a short caption. Pass multiple IDs to setFileIds()
for batch processing.