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.

Basel Issmail Basel Issmail ’m a Senior Full-Stack Developer and Tech Lead with experience designing and building scalable web platforms. I work across the full development lifecycle, from translating business requirements into technical architecture to delivering reliable production systems. My work focuses on modern web technologies, including TypeScript, Angular, Node.js, and cloud-based architectures. I enjoy solving complex technical problems and helping teams turn product ideas and prototypes into working platforms that can grow and scale. In addition to development, I often collaborate closely with product managers, business analysts, designers, and QA teams to ensure that solutions align with both technical and business goals. I enjoy working with startups and product teams where I can contribute both as a hands-on engineer and as a technical partner in designing and delivering impactful software. Bastien Labelle Bastien Labelle Full stack dev w/ 20+ years of experience Victor Denisov Victor Denisov Developer Costea Adrian Costea Adrian Embedded Engineer specilizing in perception systems. Latest project was a adas camera calibration system. Taufan Taufan I’m a product-focused engineer and tech leader who builds scalable systems and turns ideas into production-ready platforms. Over the past years, I’ve worked across startups and fast-moving teams, leading backend architecture, improving system reliability, and shipping products used by thousands of users. My strength is not just writing code — but connecting product vision, technical execution, and business impact. BurnHavoc BurnHavoc Been around fixing other peoples code for 20 years. Tejas Chokhawala Tejas Chokhawala Full-stack engineer with 5 years experience building production web apps using React, Next.js and TypeScript. Focused on performance, clean architecture and shipping fast. Experienced with Supabase/Postgres backends, Stripe billing, and building AI-assisted developer tools. Milan Surelia Milan Surelia Milan Surelia is a Mobile App Developer with 5+ years of experience crafting scalable, cross-platform apps at 7Span and Meticha. At 7Span, he engineers feature-rich Flutter apps with smooth performance and modern UI. As the Co-Founder of Meticha, he builds open-source tools and developer-focused products that solve real-world problems. Expertise: 💡 Developing cross-platform apps using Flutter, Dart, and Jetpack Compose for Android, iOS, and Web. 🖋️ Sharing insights through technical writing, blogging, and open-source contributions. 🤝 Collaborating closely with designers, PMs, and developers to build seamless mobile experiences. Notable Achievements: 🎯 Revamped the Vepaar app into Vepaar Store & CRM with a 2x performance boost and smoother UX. 🚀 Launched Compose101 — a Jetpack Compose starter kit to speed up Android development. 🌟 Open source contributions on Github & StackOverflow for Flutter & Dart 🎖️ Worked on improving app performance and user experience with smart solutions. Milan is always happy to connect, work on new ideas, and explore the latest in technology. Pratik Pratik SWE with 15+ years of experience building and maintaining web apps and extensive BE infrastructure Caio Rodrigues Caio Rodrigues I'm a full-stack developer focused on building practical and scalable web applications. My main experience is with **React, TypeScript, and modern frontend architectures**, where I prioritize clean code, component reusability, and maintainable project structures. I have strong experience working with **dynamic forms, state management (Redux / React Hook Form), and complex data-driven interfaces**. I enjoy solving real-world problems by turning ideas into reliable software that companies can actually use in their daily operations. Beyond coding, I care about **software quality and architecture**, following best practices for componentization, code organization, and performance optimization. I'm also comfortable working across the stack when needed, integrating APIs, handling business logic, and helping transform prototypes into production-ready systems. My goal is always to deliver solutions that are **simple, efficient, and genuinely useful for the people using them.**

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