подскажите как просмотреть файл (открыть его по клику). Сейчас сделал его загрузку, а просмотр не работает. Нашел вариант считывание массива байтов через FileReader, но не работает. Где я ошибаюсь?
export class File {
/**
* @param {string} encoded
* @returns {number[]}
*/
static convert(encoded) {
const binaryString = window.atob(encoded)
const binaryLen = binaryString.length
const bytes = new Uint8Array(binaryLen)
for (let i = 0; i < binaryLen; i++) {
let ascii = binaryString.charCodeAt(i)
bytes[i] = ascii
}
return bytes
}
/**
* @param {string} name
* @param {number[]} bytes
*/
static save(name, bytes) {
const blob = new Blob([bytes])
// let reader = new FileReader();
// reader.readAsArrayBuffer(blob);
const link = document.createElement("a")
const fileName = name
link.href = window.URL.createObjectURL(blob)
link.download = fileName
link.click()
link.remove()
}
/**
* @param {string} filename
* @param {string} content
*/
static download(filename, content) {
const decoded = this.convert(content)
File.save(filename, decoded)
}
}