DarkSistem
DarkSistem

Reputation: 21

Blazor Server-Side JS Invoking

Hi I'm trying to move the bytes of my video which is in c# to javascript to make the bytes into URL.createObjectURL on Blazor server-side

I moved the bytes using Js Invoke

.cs

     if (!string.IsNullOrEmpty(item.PathFile))
         {

           //Byte Video
            byte[] result = GetFile(item.PathFile);

            if (result != null)
               {                            
               
                  var url = await Js.InvokeAsync<string>("videoUrl", result);
                  data.ImageString = url;

                }
          }

.js


function videoUrl(value) {

            var byteCharacters = atob(value);
            var byteNumbers = new Array(byteCharacters.length);
            for (var i = 0; i < byteCharacters.length; i++) {
                byteNumbers[i] = byteCharacters.charCodeAt(i);
            }

            var byteArray = new Uint8Array(byteNumbers);
            //Byte Array -> Blob
            var file = new Blob([byteArray], { type: 'data:video/mp4;base64' });
            //Blob -> Object URL
            var fileURL = URL.createObjectURL(file);
           
            return fileURL;

        }

My problem is, I tried this script for a video with a size of 3 Mb it runs fine, but when I try for a 133Mb video I get an error:

Error: System.ArgumentException: The JSON value of length 139569235 is too large and not supported.

I've tried to fix it, but it still fails, it makes me a little frustrated

So is there a solution for my error ? or what should I do?

I thank you for any suggestions or feedback

Upvotes: 0

Views: 560

Answers (1)

James Drinkwater
James Drinkwater

Reputation: 406

So, reading on the AspNetDocs github, there is a startup option that can change the max message size, but I think it only applies to calls from JS to .Net (https://github.com/dotnet/AspNetCore.Docs/issues/21208). Worth a check though.

services.AddServerSideBlazor()
    .AddHubOptions(options => options.MaximumReceiveMessageSize = 32000);

Personally though, I would do as Mister Magoo said in the comment and either use an API or chunk the data and reassemble at the other end.

Upvotes: 1

Related Questions