Code testing
Modified: February 14, 2026 7:58 PM Created: September 17, 2025 3:27 PM Master Type: Notes Hide: No Starred: No Status: Unassigned
server.js
const express = require('express');
const path = require('path');
const app = express();
const PORT = 4000;
app.use('/images', express.static(path.join(__dirname, 'images')));
app.listen(PORT, () => {
console.log(`Image server running at http://localhost:${PORT}/images`);
});uploader.js
const Airtable = require('airtable');
const fs = require('fs');
const path = require('path');
const base = new Airtable({ apiKey: 'your_airtable_api_key' }).base('your_base_id');
const TABLE_NAME = 'Your Table';
const ATTACHMENT_FIELD = 'Photos';
const IMAGE_FOLDER = path.join(__dirname, 'images');
const IMAGE_SERVER_URL = 'http://localhost:4000/images';
const files = fs.readdirSync(IMAGE_FOLDER).filter(f => /\.(jpg|jpeg|png|gif)$/i.test(f));
// Split into groups of 4
const chunks = [];
for (let i = 0; i < files.length; i += 4) {
chunks.push(files.slice(i, i + 4));
}
(async () => {
for (const [index, group] of chunks.entries()) {
const attachments = group.map(filename => ({
url: `${IMAGE_SERVER_URL}/${encodeURIComponent(filename)}`
}));
try {
await base(TABLE_NAME).create([
{
fields: {
[ATTACHMENT_FIELD]: attachments
}
}
]);
console.log(`✅ Created record ${index + 1} with:`, group);
} catch (error) {
console.error(`❌ Failed to create record ${index + 1}:`, error);
}
}
})();