Skip to content

Blazor Preview4 increase buffer size #9570

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

Closed
QadiymStewart opened this issue Apr 19, 2019 · 21 comments
Closed

Blazor Preview4 increase buffer size #9570

QadiymStewart opened this issue Apr 19, 2019 · 21 comments
Assignees
Labels
area-blazor Includes: Blazor, Razor Components bug This issue describes a behavior which is not expected - a bug. Done This issue has been fixed

Comments

@QadiymStewart
Copy link

Using the new Blazor Serverside Preview 4 breaks my upload Component.

Preview 3 I was able to increase the SignalR connection buffer size using

` app.UseRouting(routes =>
        {
            routes.MapRazorPages();
            routes.MapHub<ComponentHub>(
                ComponentHub.DefaultPath,
                o =>
                {
                    o.ApplicationMaxBufferSize = 102400000; // larger size
                    o.TransportMaxBufferSize = 102400000; // larger size
                })
                .AddComponent<App>("app");
        });`

In preview 4 it has switched to endpoint routing

app.UseEndpoints(endpoints =>
           {
               endpoints.MapBlazorHub();
               endpoints.MapFallbackToPage("/_Host");
           });

How would I configure MapBlazorHub();
Related Issue #7884

@QadiymStewart QadiymStewart changed the title Blazor Preview4 Incerease buffer size Blazor Preview4 increase buffer size Apr 19, 2019
@Eilon Eilon added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Apr 19, 2019
@davidfowl
Copy link
Member

Try this:

services.AddServerSideBlazor().AddSignalR().AddHubOptions<ComponentHub>(o =>
{
    o.MaximumReceiveMessageSize = 102400000;
});

@QadiymStewart
Copy link
Author

Try this:
services.AddServerSideBlazor().AddSignalR().AddHubOptions(o =>
{
o.MaximumReceiveMessageSize = 102400000;
});

That doesn't seem to resolve the issue. I can confirm its not my code because I made an image under the buffer size and it uploads fine.

Javasciprt error
error

My javascript code
JsInterop sending back DataUrl as image data.

 const readUploadedFileAsText = (inputFile) => {
 const temporaryFileReader = new FileReader();

 return new Promise((resolve, reject) => {
    temporaryFileReader.onerror = () => {
        temporaryFileReader.abort();
        reject(new DOMException("Problem parsing input file."));
    };

    temporaryFileReader.onload = () => {
        resolve(temporaryFileReader.result);
    };

    temporaryFileReader.readAsDataURL(inputFile);
    });
};

   UploadFiles = async (instance, fileInput) => {
   const files = Array.from(fileInput.files);
   files.map(async image => {
   var imagedata = await readUploadedFileAsText(image);

    instance.invokeMethodAsync('GetUploadedFiles', imagedata);
    });
 };

My C# Code

public async Task UploadFile()
    {
        await JSRuntime.InvokeAsync<object>("UploadFiles", new DotNetObjectRef(this), fileUpload);
    }

    [JSInvokable]
    public void GetUploadedFiles(string message)
    {
        ImageDataSources.Add(message);
        var image = new CreateImageDto();
        image.Data = message;
        image.Position = ImageDataSources.Count;
        image.FileName = Guid.NewGuid().ToString();
        CreateImageDtos.Add(image);

        StateHasChanged();
    }

@danroth27 danroth27 added the area-blazor Includes: Blazor, Razor Components label Apr 22, 2019
@danroth27 danroth27 added this to the 3.0.0-preview6 milestone Apr 22, 2019
@danroth27 danroth27 added the enhancement This issue represents an ask for new feature or an enhancement to an existing one label Apr 22, 2019
@davidfowl
Copy link
Member

Are you sure you're hitting a size limit then? How big is the image?

@QadiymStewart
Copy link
Author

QadiymStewart commented Apr 23, 2019

@davidfowl Not very big. Tested with 5kb - 13kb. Before was able to upload 6mb plus images. Looking further into things seems like it could also be that the dataurl string is too long. Simplified test repo is located here https://dev.azure.com/twinnaz/_git/BlazorBug

@tmayonez
Copy link

I've got the same problem. I've investigated that it's not because MaximumReceiveMessageSize. It is impossible to invoke .NET method from javascript if parameters passed to method are to big. I guess, the limit of parameters serialized to JSON during invokeMethodAsync is 4KB. Worked fine before preview 4.

@Tewr
Copy link

Tewr commented May 1, 2019

Dedicated server-side project with simple tester on first page to reproduce:

https://github.com/Tewr/Bug9570Repro

@mkArtakMSFT mkArtakMSFT added bug This issue describes a behavior which is not expected - a bug. and removed enhancement This issue represents an ask for new feature or an enhancement to an existing one labels May 1, 2019
@mkArtakMSFT mkArtakMSFT assigned javiercn and unassigned pranavkm May 1, 2019
@mkArtakMSFT
Copy link
Contributor

@javiercn assigning this to you as you have couple of similar issues on your plate already: #9683 and #9808.

@javiercn
Copy link
Member

javiercn commented May 2, 2019

This can be done today in the same way with endpoint routing.

endpoints.MapHub<ComponentHub>(
                ComponentHub.DefaultPath,
                o =>
                {
                    o.ApplicationMaxBufferSize = 102400000; // larger size
                    o.TransportMaxBufferSize = 102400000; // larger size
                })
                // .AddComponent<App>("app");

For the record, in the future we plan to hide the specific hub we use and expose all the SignalR configuration options on MapBlazorHub.

@javiercn javiercn closed this as completed May 2, 2019
@tn-5
Copy link

tn-5 commented May 2, 2019

@javiercn Can you please explain exactly how this can be done today? Adding the snippet above does not work, but I may well be doing something incorrectly.

@QadiymStewart
Copy link
Author

@javiercn Adding the above code gives error in console.

app.UseEndpoints(endpoints =>
        {
            endpoints.MapHub<ComponentHub>(
            ComponentHub.DefaultPath,
            o =>
            {
                o.ApplicationMaxBufferSize = 102400000; // larger size
                o.TransportMaxBufferSize = 102400000; // larger size
            });
            endpoints.MapBlazorHub();

            endpoints.MapFallbackToPage("/_Host");
        });

bbug1

Adding on the BlazorHub doesn't compile.

Compiler Error Message: CS1660: Cannot convert lambda expression to type 'string' because it is not a delegate type

 app.UseEndpoints(endpoints =>
        {
          
            endpoints.MapBlazorHub<ComponentHub>(
            ComponentHub.DefaultPath,
            o =>
            {
                o.ApplicationMaxBufferSize = 102400000; // larger size
                o.TransportMaxBufferSize = 102400000; // larger size
            });

            endpoints.MapFallbackToPage("/_Host");
        });

@QadiymStewart
Copy link
Author

@javiercn @mkArtakMSFT If possible can you provide a working repo to test.

@rynowak rynowak reopened this May 2, 2019
@davidfowl
Copy link
Member

@javiercn that no longer will prevent the size limit from being hit but it's not being hit in this issue.

@Tewr
Copy link

Tewr commented May 2, 2019

@javiercn: I pushed your workaround to a new branch
https://github.com/Tewr/Bug9570Repro/tree/MapHubWorkAround/ , but the behaviour is the same as with default setup MapBlazorHub().

@QadiymStewart QadiymStewart reopened this May 7, 2019
@mkArtakMSFT mkArtakMSFT removed the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label May 9, 2019
@mkArtakMSFT mkArtakMSFT removed the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label May 9, 2019
@javiercn javiercn removed the Working label May 30, 2019
@mkArtakMSFT
Copy link
Contributor

Moving this to Preview7 to spend some more time and investigate what's going on here.

@javiercn
Copy link
Member

I submitted a PR to add overloads that allow configuring this (somehow they got lost).

I expect the issues in json serialization issue to go away with @pranavkm changes

@javiercn javiercn added Done This issue has been fixed and removed Working labels May 31, 2019
@davidfowl
Copy link
Member

I think we exposed the wrong options here. There are a new set of options in 3.0 to increase the message size

@javiercn
Copy link
Member

javiercn commented Jun 1, 2019

@davidfowl :( what should it be then? This is what we were doing before.

@davidfowl
Copy link
Member

@javiercn
Copy link
Member

javiercn commented Jun 1, 2019

That’s fine, but I imagine that is global and this is local to the endpoint. Isn’t it?

Independent of that setting I would expect it will still be valuable to configure this and other things on the endpoint.

We should not hide the underlying hub endpoint configuration.

@davidfowl
Copy link
Member

That’s fine, but I imagine that is global and this is local to the endpoint. Isn’t it?

No, the configuration that was the max buffer size before is just an optimization now.

Independent of that setting I would expect it will still be valuable to configure this and other things on the endpoint.

Sure it's not "bad" to expose this setting, it just doesn't do what you think it does and I'd imagine is going to be much less useful to set in the future.

@julienGrd
Copy link

julienGrd commented Jul 29, 2019

[EDIT] : I find the solution for preview 7 in another post, i put the solution bellow

pServices.AddServerSideBlazor()
            .AddHubOptions(o =>
             {
                 o.MaximumReceiveMessageSize = 102400000;
             });

Hi guys, i'm currently under preview 7 (server-side version) and i meet the same problem.
i try to send a base64 string wich represent an image from js to one of my components (with JSInvokable).
I try tu use code you suggest on this post but I have reference problem (maybe this workaround is outdated ?)

endpoints.MapBlazorHub<ComponentHub>(
                    ComponentHub.DefaultPath,
                    o =>
                    {
                        o.ApplicationMaxBufferSize = 102400000; // larger size
                        o.TransportMaxBufferSize = 102400000; // larger size
                    });

I'm unable to resolve ComponentHub. When i check what's expected, it's seem to be a IComponent (so my root Component ?)

I don't understand what can i done now to bypass the problem

thanks for your help !

@ghost ghost locked as resolved and limited conversation to collaborators Dec 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components bug This issue describes a behavior which is not expected - a bug. Done This issue has been fixed
Projects
None yet
Development

No branches or pull requests