Fix: Resolved E2BIG error by switching to file-based payload passing for large requests (images)

This commit is contained in:
2026-01-03 13:44:18 +00:00
parent 6bde387760
commit 0761c05b62
2 changed files with 38 additions and 10 deletions

View File

@@ -48,15 +48,25 @@ app.post('/api/run', (req, res) => {
return res.status(400).json({ error: 'Mode is required' });
}
// Convert payload to a JSON string and then to a Base64 string to ensure safe command line passing
const payloadString = JSON.stringify(payload);
const payloadBase64 = Buffer.from(payloadString).toString('base64');
// E2BIG FIX: Write payload to a temporary file instead of passing via command line args
const tmpDir = path.join(__dirname, 'tmp');
if (!fs.existsSync(tmpDir)) {
fs.mkdirSync(tmpDir);
}
const payloadFilePath = path.join(tmpDir, `payload_${Date.now()}_${Math.random().toString(36).substring(7)}.json`);
try {
fs.writeFileSync(payloadFilePath, JSON.stringify(payload));
} catch (err) {
console.error("Failed to write payload file:", err);
return res.status(500).json({ error: "Failed to process request payload." });
}
const pythonScriptPath = path.join(__dirname, 'gtm_architect_orchestrator.py');
const pythonProcess = spawn('python3', [
pythonScriptPath,
'--mode', mode,
'--payload_base64', payloadBase64
'--payload_file', payloadFilePath // Use file path instead of base64 string
]);
let stdoutData = '';
@@ -76,6 +86,13 @@ app.post('/api/run', (req, res) => {
});
pythonProcess.on('close', (code) => {
// Cleanup temp file
try {
if (fs.existsSync(payloadFilePath)) fs.unlinkSync(payloadFilePath);
} catch (e) {
console.error("Failed to delete temp payload file:", e);
}
if (code !== 0) {
console.error(`Python script exited with code ${code}`);
console.error('Stderr:', stderrData);