Код: Выделить всё
@code {
private async Task HandleDrop(DragEventArgs args)
{
var files = args.DataTransfer.Files;
// Do something to upload the file and get the content
}
По-видимому, изначально нет способа получить содержимое этих файлов.
Поэтому я попытался добиться этого с помощью взаимодействия с JavaScript:
Код: Выделить всё
private async Task HandleDrop(DragEventArgs args)
{
var content = await jsRuntime.InvokeAsync("getContentFromFile", args);
}
Код: Выделить всё
async function getContentFromFile(args) {
// Use some API here? File Upload API? Didn't work as args is only a data object and not the "real" DragEventArgs from JavaScript
// I also tried FileReader
const fileName = args.Files[0]; // Let's assume we always have one file
let content = await new Promise((resolve) => {
let fileReader = new FileReader();
fileReader.onload = (e) => resolve(fileReader.result);
fileReader.readAsText(fileName);
});
console.log(content);
return content;
}
параметр не имеет типа «Blob»
Возможно ли это при таком подходе с текущей версией blazor (.net6) вообще? Любые советы приветствуются.
Подробнее здесь: https://stackoverflow.com/questions/705 ... loads-file
Мобильная версия