Greetings! Currently, I am attempting to convert the bytes of my video from C# to JavaScript in order to transform them into URL.createObjectURL on a Blazor server-side application.
I managed to move 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;
}
However, I encountered an issue where the script works fine for a video with a size of 3 Mb, but gives an error when trying it on a 133Mb video:
Error: System.ArgumentException: The JSON value of length 139569235 is too large and not supported.
Despite my efforts to resolve this issue, it continues to fail, leaving me slightly frustrated. Can anyone provide a solution or offer any advice?
Your suggestions and feedback are greatly appreciated!