Claude Code storage

Binary Files Corrupted During Upload or Processing

Files uploaded to or processed by your application come out corrupted. PDFs are unreadable, images show as broken, ZIP archives can't be extracted, and Excel files fail to open. The files appear to be the right size but their contents are garbled.

Binary file corruption typically happens when the application treats binary data as text (applying encoding transformations that destroy the data), when streams are not properly piped, or when files are read and written with mismatched encoding settings.

This issue is particularly insidious because it may only affect certain file types or file sizes, making it hard to reproduce consistently during testing.

Error Messages You Might See

Error: Invalid PDF structure The file is corrupted and cannot be opened Error: incorrect header check (zlib) CairoError: invalid image surface Corrupted ZIP: unexpected end of data
Error: Invalid PDF structureThe file is corrupted and cannot be openedError: incorrect header check (zlib)CairoError: invalid image surfaceCorrupted ZIP: unexpected end of data

Common Causes

  • UTF-8 encoding applied to binary data — Reading binary files with encoding: 'utf-8' instead of as a Buffer or bytes object
  • Base64 double-encoding — File data is base64 encoded during upload and encoded again during storage, doubling the corruption
  • Multipart parsing misconfigured — The file upload middleware converts binary data to strings instead of preserving raw buffers
  • Stream not set to binary mode — HTTP response or file stream uses text mode instead of binary mode
  • Chunked transfer truncation — Large files are cut off because the receiving end closes the connection before all chunks arrive

How to Fix It

  1. Always use binary mode for file operations — Use fs.readFile without encoding option (returns Buffer) or open files with 'rb'/'wb' in Python
  2. Verify multipart parsing configuration — Ensure multer, busboy, or your upload library preserves raw binary buffers
  3. Test with actual binary files — Upload a real PDF, image, and ZIP file and verify they open correctly after download. Compare checksums
  4. Use streams correctly — Pipe readable streams directly to writable streams without intermediate string conversion
  5. Check Content-Type headers — Ensure the response sets application/octet-stream or the correct MIME type, not text/plain

Real developers can help you.

Dor Yaloz Dor Yaloz SW engineer with 6+ years of experience, I worked with React/Node/Python did projects with React+Capacitor.js for ios Supabase expert Bastien Labelle Bastien Labelle Full stack dev w/ 20+ years of experience David Olverson David Olverson Solo dev shipping production apps with AI-assisted development. I specialize in rescuing broken Lovable/Bolt/Cursor builds and taking them to production. 10+ apps shipped including SaaS CRMs, gaming platforms, real estate tools, and Discord bots. Stack: Next.js 16, TypeScript, Tailwind CSS, FastAPI, PostgreSQL, Prisma. I use Claude Code with 50+ custom skills for rapid delivery. Average turnaround: 2-4 weeks from broken prototype to production. Alvin Voo Alvin Voo I’ve watched the tech landscape evolve over the last decade—from the structured days of Java Server Pages to the current "wild west" of Agentic-driven development. While AI can "vibe" a frontend into existence, I specialize in the architecture that keeps it from collapsing. My expertise lies in the critical backend infrastructure: the parts that must be fast, secure, and scalable. I thrive on high-pressure environments, such as when I had only three weeks to architect and launch an Ethereum redemption system with minimal prior crypto knowledge, turning it into a major revenue stream. What I bring to your project: Forensic Debugging: I don't just "patch" bugs; I use tools like Datadog and Explain Analyzers to map out bottlenecks and resolve root causes—like significantly reducing memory usage by optimizing complex DB joins. Full-Stack Context: Deep experience in Node.js and React, ensuring backends play perfectly with mobile and web teams. Sanity in the Age of AI: I bridge the gap between "best practices" and modern speed, ensuring your project isn't just built fast, but built to last. Mehdi Ben Haddou Mehdi Ben Haddou - Founder of Chessigma (1M+ users) & many small projects - ex Founding Engineer @Uplane (YC F25) - ex Software Engineer @Amazon and @Booking.com Vlad Temian Vlad Temian 15+ years shipping production infrastructure for startups. Former CTO at qed.builders (acquired by The Sandbox). Cursor ambassador and agentic tooling builder. I've scaled systems, automated deployments, and built observability tools for AI coding workflows. I specialize in taking vibe-coded apps from broken prototype to production-ready: fixing Supabase auth/RLS, Stripe integrations, deployment pipelines, and cleaning up AI-generated spaghetti. I build tools in this space (agentprobe, claudebin, micode) and understand both sides: how AI generates code and why it breaks. https://blog.vtemian.com/ Omar Faruk Omar Faruk As a Product Engineer at Klasio, I contributed to end-to-end product development, focusing on scalability, performance, and user experience. My work spanned building and refining core features, developing dynamic website templates, integrating secure and reliable payment gateways, and optimizing the overall system architecture. I played a key role in creating a scalable and maintainable platform to support educators and learners globally. I'm enthusiastic about embracing new challenges and making meaningful contributions. Pratik Pratik SWE with 15+ years of experience building and maintaining web apps and extensive BE infrastructure Meïr Ankri Meïr Ankri Full-stack developer specializing in React / Next.js / Node.js with 6+ years of experience. I've worked across various sectors including automotive (Reezocar/Société Générale), healthcare (Medical Link SaaS), and e-commerce (Glasman). I build web apps end-to-end, from architecture to production, with a focus on scalability, performance, and code quality. I also mentor junior developers and contribute to technical decisions and code reviews. Anthony Akpan Anthony Akpan Developer with 8 years of experience building softwares fro startups

You don't need to be technical. Just describe what's wrong and a verified developer will handle the rest.

Get Help

Frequently Asked Questions

Why are my uploaded files corrupted?

The most common cause is reading binary files as text (UTF-8). Ensure your upload handler preserves raw binary buffers. In Node.js, don't pass an encoding option to fs.readFile for binary files.

How do I verify file integrity after upload?

Compare MD5 or SHA256 checksums of the original file and the stored file. If they differ, the data was modified during transit or storage. Use crypto.createHash in Node.js or hashlib in Python.

Related Claude Code Issues

Can't fix it yourself?
Real developers can help.

You don't need to be technical. Just describe what's wrong and a verified developer will handle the rest.

Get Help