“Angular GET BASE64 из файла” Ответ

угловой преобразование файла в Base64

handleUpload(event) {
    const file = event.target.files[0];
    const reader = new FileReader();
    reader.readAsDataURL(file);
    reader.onload = () => {
        console.log(reader.result);
    };
}
Zany Zebra

Angular GET BASE64 из файла

  convertFile(file: File): Observable<string> {
    const result = new ReplaySubject<string>(1);
    const reader = new FileReader();
    reader.readAsBinaryString(file);
    reader.onload = (event) => result.next(btoa(reader.result.toString()));
    return result;
  }
	
this.convertFile(event.target.files[0]).subscribe(base64 => {
	this.base64Output = base64;
});
/// NOTE ///
// The event.target.files is just the File Object e.g. from a
// <input type="file"> form
// you can also create a file with the following command:
var f = new File([""], "filename");


JBTheOneAndOnly

Ответы похожие на “Angular GET BASE64 из файла”

Вопросы похожие на “Angular GET BASE64 из файла”

Больше похожих ответов на “Angular GET BASE64 из файла” по JavaScript

Смотреть популярные ответы по языку

Смотреть другие языки программирования