I need to record some audio, maybe even video, using Media API in JS, example for Blazor. Then, I would like to pass recorded Blob content from JS to Blazor. As far as this is audio or video content, it can be pretty big.
What I have tried so far
Encoding data as ANSI string or passing an array of integers. This results in
InvalidDataException, SignalR disconnect, timeout, after a minute or so SignalR gets back to life and C# receivesnullEncoding data as base 64 or passing
UInt8Array. Outcome is the same.Passing
Blob,ArrayBuffer, orFormDatadirectly from JS. This results in empty objectValueKind: {}in C#.
The source of JS call
recorder.stop();
recorder.exportWAV(async blob => {
const content = await (new Response(blob).arrayBuffer());
const contentNums = new Uint8Array(content);
const contentCodes = new TextDecoder('windows-1252').decode(contentNums);
const data = new FormData();
data.append('file', blob, 'Demo');
//success(window.URL.createObjectURL(blob));
console.log(blob)
console.log(content)
console.log(contentNums)
console.log(contentCodes)
success(Array.from(contentNums));
})
The source of C# interop call
private IJSRuntime _scriptRuntime = null;
public async Task<dynamic> GetMedia<dynamic>()
{
return await _scriptRuntime.InvokeAsync<dynamic>('AudioFunctions.GetMediaFile');
}
Is there a way to pass large byte arrays or at least strings from JS to Blazor.NET?