BlazorInputFile icon indicating copy to clipboard operation
BlazorInputFile copied to clipboard

Uploaded .zip Files are corrupted

Open agoodnap opened this issue 5 years ago • 3 comments

Hey, I've been trying to upload a .zip file using Inputfile, but while the upload completes without a problem, I cannot open the .zip file afterwards. The file size after the upload is identical to the one before, so I'm not sure what the reason could be. Any ideas?

agoodnap avatar May 14 '20 05:05 agoodnap

Are you using StreamReader? WASM or Server Blazor?

TotzkePaul avatar Aug 16 '20 00:08 TotzkePaul

I see the same thing when using this (I added an MD5 computation across the pipeline to narrow down the corruption to here)

` private async Task DropFile(IFileListEntry[] files) { var file = files.FirstOrDefault(); if (file != null) { status = "Loading...";

        byte[] data = new byte[file.Data.Length];
        await file.Data.ReadAsync(data, 0, data.Length);
        string hash = data.ToMD5();`

devnu11 avatar Sep 10 '20 20:09 devnu11

Found the solution (or workaround) was to use:

using var ms = new MemoryStream(); await file.Data.CopyToAsync(ms); var data = ms.ToArray();

Instead of: //byte[] data = new byte[file.Data.Length]; //await file.Data.ReadAsync(data, 0, data.Length);

devnu11 avatar Sep 10 '20 21:09 devnu11