【发布时间】:2021-07-14 03:06:10
【问题描述】:
我需要录制一些音频,甚至可能是视频,在 JS 中使用 Media API,在 Blazor 中使用 example。然后,我想将录制的 Blob 内容从 JS 传递到 Blazor。就音频或视频内容而言,它可能非常大。
到目前为止我已经尝试过什么
-
将数据编码为ANSI 字符串或传递整数数组。这导致
InvalidDataException,SignalR 断开连接,超时,大约一分钟后 SignalR 恢复正常,C# 接收到null -
将数据编码为base 64 或传递
UInt8Array。结果是一样的。 -
直接从 JS 传递
Blob、ArrayBuffer或FormData。这会在 C# 中产生空对象ValueKind: {}。
JS调用的来源
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));
})
C#互操作调用的来源
private IJSRuntime _scriptRuntime = null;
public async Task<dynamic> GetMedia<dynamic>()
{
return await _scriptRuntime.InvokeAsync<dynamic>('AudioFunctions.GetMediaFile');
}
有没有办法将大字节数组或至少是字符串从 JS 传递到 Blazor.NET?
【问题讨论】: