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
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
- Always use Buffer for binary files — Never call toString() on file data. Use Buffer objects or ArrayBuffer throughout the upload pipeline
- 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
- Avoid double-encoding — Check if your storage client already handles encoding. Don't base64-encode if the client expects a Buffer or stream
- Pipe streams directly — Instead of reading the entire file into memory, pipe the upload stream directly to the storage write stream
- 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
- 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.
You don't need to be technical. Just describe what's wrong and a verified developer will handle the rest.
Get HelpFrequently 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.