Windsurf storage

Blob Storage Corrupting Uploaded Files in Windsurf App

Files uploaded to blob storage through your Windsurf-generated app become corrupted when downloaded. PDFs are unreadable, images show garbled data, ZIP files fail to extract, and documents open as random characters. The upload appears to succeed, but the stored file is damaged.

This is a particularly insidious bug because uploads appear successful — no errors are thrown, the file shows up in storage, and the file size may even look correct. But when a user downloads and opens the file, it's broken.

The corruption typically affects binary files (images, PDFs, ZIPs) while text files may work fine, which is a strong clue that the issue is related to encoding or stream handling.

Error Messages You Might See

Error: Invalid or corrupted PDF Failed to decode image Error: End-of-central-directory signature not found (ZIP) The file is damaged and could not be opened UTF-8 decode error on binary data
Error: Invalid or corrupted PDFFailed to decode imageError: End-of-central-directory signature not found (ZIP)The file is damaged and could not be openedUTF-8 decode error on binary data

Common Causes

  • UTF-8 encoding applied to binary data — Cascade read the file as a UTF-8 string instead of a Buffer, destroying binary data during encoding conversion
  • Base64 double-encoding — The file is base64-encoded before upload, but the storage client also encodes it, resulting in double-encoded data
  • Wrong content-type on upload — The file is uploaded with content-type: text/plain or application/json instead of its actual MIME type
  • Stream not piped correctly — The readable stream is consumed (read to string) before being passed to the storage upload, instead of being piped directly
  • Multipart boundary parsing error — The multipart form parser mishandles the file boundaries, truncating or appending extra bytes

How to Fix It

  1. Always use Buffer for binary files — Never call toString() on file data. Use Buffer objects or ArrayBuffer throughout the upload pipeline
  2. Set the correct content-type — Detect the MIME type using the file-type library or the upload's mimetype field, and pass it to the storage upload call
  3. Avoid double-encoding — Check if your storage client already handles encoding. Don't base64-encode if the client expects a Buffer or stream
  4. Pipe streams directly — Instead of reading the entire file into memory, pipe the upload stream directly to the storage write stream
  5. Verify with checksums — Generate an MD5 hash before upload and after download to confirm the file is identical. If hashes differ, the corruption is in the upload path
  6. Test with binary files specifically — Upload a small PNG or PDF and download it immediately. Open it to verify integrity before shipping to production

Real developers can help you.

Sage Fulcher Sage Fulcher Hey I'm Sage! Im a Boston area software engineer who grew up in South Florida. Ive worked at a ton of cool places like a telehealth kidney care startup that took part in a billion dollar merger (Cricket health/Interwell health), a boutique design agency where I got to work on a ton of exciting startups including a photography education app, a collegiate Esports league and more (Philosophie), a data analytics as a service startup in Cambridge (MA) as well as at Phillips and MIT Lincoln Lab where I designed and developed novel network security visualizations and analytics. I've been writing code and furiously devoted to using computers to make people’s lives easier for about 17 years. My degree is in making computers make pretty lights and sounds. Outside of work I love hip hop, the Celtics, professional wrestling, magic the gathering, photography, drumming, and guitars (both making and playing them) 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. Matthew Jordan Matthew Jordan I've been working at a large software company named Kainos for 2 years, and mainly specialise in Platform Engineering. I regularly enjoy working on software products outside of work, and I'm a huge fan of game development using Unity. I personally enjoy Python & C# in my spare time, but I also specialise in multiple different platform-related technologies from my day job. Matt Butler Matt Butler Software Engineer @ AWS 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 Franck Plazanet Franck Plazanet I am a Strategic Engineering Leader with over 8 years of experience building high-availability enterprise systems and scaling high-performing technical teams. My focus is on bridging the gap between complex technology and business growth. Core Expertise: 🚀 Leadership: Managing and coaching teams of 15+ engineers, fostering a culture of accountability and continuous improvement. 🏗️ Architecture: Enterprise Core Systems, Multi-system Integration (ERP/API/ETL), and Core Database Structure. ☁️ Cloud & Scale: AWS Expert; architected systems handling 10B+ monthly requests and managing 100k+ SKUs. 📈 Business Impact: Aligning tech strategy with P&L goals to drive $70k+ in monthly recurring revenue. I thrive on "out-of-the-box" thinking to solve complex technical bottlenecks and am always looking for ways to use automation to improve business productivity. Jaime Orts-Caroff Jaime Orts-Caroff I'm a Senior Android developer, open to work in various fields Richard McSorley Richard McSorley Full-Stack Software Engineer with 8+ years building high-performance applications for enterprise clients. Shipped production systems at Walmart (4,000+ stores), Cigna (20M+ users), and Arkansas Blue Cross. 5 patents in retail/supply chain tech. Currently focused on AI integrations, automation tools, and TypeScript-first architectures. Daniel Vázquez Daniel Vázquez Software Engineer with over 10 years of experience on Startups, Government, big tech industry & consulting. Prakash Prajapati Prakash Prajapati I’m a Senior Python Developer specializing in building secure, scalable, and highly available systems. I work primarily with Python, Django, FastAPI, Docker, PostgreSQL, and modern AI tooling such as PydanticAI, focusing on clean architecture, strong design principles, and reliable DevOps practices. I enjoy solving complex engineering problems and designing systems that are maintainable, resilient, and built to scale.

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 do text files upload fine but images get corrupted?

Text files survive UTF-8 encoding because they're already text. Binary files (images, PDFs, ZIPs) contain byte sequences that are invalid UTF-8, so encoding them as strings destroys the data. Always handle binary files as Buffers.

How can I tell if corruption happens during upload or download?

Check the file directly in your storage dashboard (S3 console, Supabase dashboard). Download it from there. If it's corrupt in storage, the upload is the problem. If it's fine in storage but corrupt when downloaded through your app, the download handler is the issue.

Related Windsurf 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