“Przesłanie pliku w Angular 10” Kod odpowiedzi

Prześlij pliki z Angular

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

Przesłanie pliku w 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

Odpowiedzi podobne do “Przesłanie pliku w Angular 10”

Pytania podobne do “Przesłanie pliku w Angular 10”

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu