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.

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. 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. Jared Hasson Jared Hasson Full time lead founding dev at a cyber security saas startup, with 10 yoe and a bachelor's in CS. Building & debugging software products is what I've spent my time on for forever zipking zipking I am a technologist and product builder dedicated to creating high-impact solutions at the intersection of AI and specialized markets. Currently, I am focused on PropScan (EstateGuard), an AI-driven SaaS platform tailored for the Japanese real estate industry, and exploring the potential of Archify. As an INFJ-T, I approach development with a "systems-thinking" mindset—balancing technical precision with a deep understanding of user needs. I particularly enjoy the challenge of architecting Vertical AI SaaS and optimizing Small Language Models (SLMs) to solve specific, real-world business problems. Whether I'm in a CTO-level leadership role or hands-on with the code, I thrive on building tools that turn complex data into actionable value. Bastien Labelle Bastien Labelle Full stack dev w/ 20+ years of experience Jaime Orts-Caroff Jaime Orts-Caroff I'm a Senior Android developer, open to work in various fields AUXLE AUXLE I am a Full Stack Developer experienced in building Websites, Web apps and Cross Platform Mobile Apps for Startups and Companies. 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. 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.** Jen Jacobsen Jen Jacobsen I’m a Full-Stack Developer with over 10 years of experience building modern web and mobile applications. I enjoy working across the full product lifecycle — turning ideas into real, well-built products that are intuitive for users and scalable for businesses. I particularly enjoy building mobile apps, modern web platforms, and solving complex technical problems in a way that keeps systems clean, reliable, and easy to maintain.

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