“Загрузка файла в Angular 10” Ответ

Загрузить файлы с помощью угловой

fileChange(element) {
  this.uploadedFiles = element.target.files;
}

upload() {
  let formData = new FormData();
  for (var i = 0; i < this.uploadedFiles.length; i++) {
    formData.append("uploads[]", this.uploadedFiles[i], this.uploadedFiles[i].name);
  }
  this.http.post('/api/upload', formData)
    .subscribe((response) => {
    console.log('response received is ', response);
  })
}
Disturbed Dunlin

Загрузка файла в Angular 10

onFileChange(event) {
    const reader = new FileReader();

    if (event.target.files && event.target.files.length) {
      const [file] = event.target.files;
      reader.readAsDataURL(file);
      reader.onload = () => {
        this.data.parentForm.patchValue({
          tso: reader.result
        });

        // need to run CD since file load runs outside of zone
        this.cd.markForCheck();
      };
    }
  }
Zany Zebra

Ответы похожие на “Загрузка файла в Angular 10”

Вопросы похожие на “Загрузка файла в Angular 10”

Больше похожих ответов на “Загрузка файла в Angular 10” по TypeScript

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

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