Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReadAsync dont work when Release #103

Closed
lulikin opened this issue Jan 14, 2020 · 5 comments
Closed

ReadAsync dont work when Release #103

lulikin opened this issue Jan 14, 2020 · 5 comments
Labels
need more info Request or question needs to be completed with more info from poster possible-blazor-issue This possibly a problem in the blazor framework that needs a workaround or a bugfix in blazor itself

Comments

@lulikin
Copy link

lulikin commented Jan 14, 2020

function
public Task ReadAsync(byte[] buffer, int offset, int count)
works correctly, when I'm in debug mode, but when I'm in release mode or when I publish blazor web assembly project, that function always return 0.
Here is my code :
```
var fs = await files.FirstOrDefault().OpenReadAsync();
Console.WriteLine(fs.Length);
byte[] data = new byte[fs.Length];

        long filepos = 0;
        _IsProgressOpened = true;
        byte[] buffer = new byte[1024 * 10];
        using (MemoryStream ms = new MemoryStream())
        {
            int read;
            while ((read = await fs.ReadAsync(buffer, 0, buffer.Length)) != 0)
            {
                filepos += 1024 * 10;
                progresval = (int)(filepos * 100 / fs.Length);
                StateHasChanged();
                ms.Write(buffer, 0, read);
                Console.WriteLine("Buffer length " + read);
            }
            Console.WriteLine("File uploaded");
            service.Motive = ms.ToArray();
            Console.WriteLine("File length : " + service.Motive.Length);
            service.MotiveOriginalFileName = originalfilename;
        }
        _IsProgressOpened = false;
        StateHasChanged();

**Expected behavior**
Function should work.

**Project type**
Client side

**Environment**
 - Browser: doesn't matter
 - Version of Blazor.FileReader: 1.2.0.19363
 - Version of .net sdk: 3.1.100
@Tewr
Copy link
Owner

Tewr commented Jan 15, 2020

Sounds like a framework bug but sounds can be deceiving. Ill try to find the time to reproduce in the coming days.

Could you create a small project that reproduces this? Or at least post your full setup? Your setup could possibly affect this - there has been some issues in the framework regarding static resources and release/publish

@Tewr Tewr added the possible-blazor-issue This possibly a problem in the blazor framework that needs a workaround or a bugfix in blazor itself label Jan 15, 2020
@Tewr
Copy link
Owner

Tewr commented Jan 15, 2020

Try the solution in #97 and see if this works for you

Thought it sounded familiar

@Tewr Tewr added the need more info Request or question needs to be completed with more info from poster label Jan 16, 2020
@Tewr
Copy link
Owner

Tewr commented Jan 16, 2020

I can't reproduce this. Please provide a full repro project.

@lulikin
Copy link
Author

lulikin commented Jan 30, 2020

I changed code. It was working till now (Blazor 3.2)

var x = fileReaderService.CreateReference(inputTypeFileElement);
        var files = await fileReaderService.CreateReference(inputTypeFileElement).EnumerateFilesAsync();
        var originalfilename = await jsRuntime.InvokeAsync<string>("getFileNameFromId", inputTypeFileElement);
        if (true)//(files.Count() == 1)
        {
            this.StateHasChanged();
            //var fs = await files.FirstOrDefault().OpenReadAsync();
            //Console.WriteLine(fs.Length);
            //byte[] data = new byte[fs.Length];
            //long filepos = 0;
            _IsProgressOpened = true;
            //byte[] buffer = new byte[1024 * 10];

            service.Motive = (await files.FirstOrDefault().CreateMemoryStreamAsync()).ToArray();
            service.MotiveOriginalFileName = originalfilename;

            //using (MemoryStream ms = new MemoryStream())
            //{
            //    int read;
            //    while ((read = await fs.ReadAsync(buffer, 0, buffer.Length)) > 0)
            //    {
            //        filepos += 1024 * 10;
            //        progresval = (int)(filepos * 100 / fs.Length);
            //        StateHasChanged();
            //        ms.Write(buffer, 0, read);
            //    }
            //    service.Motive = ms.ToArray();
            //    service.MotiveOriginalFileName = originalfilename;
            //}
            _IsProgressOpened = false;
            StateHasChanged();
        }

Now I have problem with 'Blazor.platform.findMethod' in javascript, but I see, that this promlem is beeing investigated in another thread.

@Tewr
Copy link
Owner

Tewr commented Jan 30, 2020

I'm closing this as the original issue is resolved

@Tewr Tewr closed this as completed Jan 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need more info Request or question needs to be completed with more info from poster possible-blazor-issue This possibly a problem in the blazor framework that needs a workaround or a bugfix in blazor itself
Projects
None yet
Development

No branches or pull requests

2 participants