Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

upload files with 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);
  })
}
Comment

upload file angular

<input type="file" class="file-upload" (change)="functionName($event)">
Comment

file upload in angular 10 post

onFileSelected(event) {
    if(event.target.files.length > 0) 
     {
       this.myForm.patchValue({
          fileName: event.target.files[0],
       })
     }
  }

submit(){
    const formData = new FormData();
    formData.append('file', this.myForm.get('fileName').value);
   
    this.http.post('http://localhost:3000/upload', formData)
      .subscribe(res => {
        console.log(res);
        alert('Uploaded Successfully.');
      })
  }
Comment

image file upload in angular

import { Component, OnInit } from '@angular/core';
import { FileUploadService } from './file-upload.service';
  
@Component({
    selector: 'app-file-upload',
    templateUrl: './file-upload.component.html',
    styleUrls: ['./file-upload.component.css']
})
export class FileUploadComponent implements OnInit {
  
    // Variable to store shortLink from api response
    shortLink: string = "";
    loading: boolean = false; // Flag variable
    file: File = null; // Variable to store file
  
    // Inject service 
    constructor(private fileUploadService: FileUploadService) { }
  
    ngOnInit(): void {
    }
  
    // On file Select
    onChange(event) {
        this.file = event.target.files[0];
    }
  
    // OnClick of button Upload
    onUpload() {
        this.loading = !this.loading;
        console.log(this.file);
        this.fileUploadService.upload(this.file).subscribe(
            (event: any) => {
                if (typeof (event) === 'object') {
  
                    // Short link via api response
                    this.shortLink = event.link;
  
                    this.loading = false; // Flag variable 
                }
            }
        );
    }
}
Comment

file upload in 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();
      };
    }
  }
Comment

angular file upload

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);
    })
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to comments in json file 
Javascript :: node js vs jquery 
Javascript :: js comparison operators 
Javascript :: javascript filter map array of objects 
Javascript :: setAttribute is not a function jquery 
Javascript :: isprime js 
Javascript :: how to create node js server 
Javascript :: javascript prevent an event to triggering multiple times 
Javascript :: sequelize bulk update 
Javascript :: @apify/http-request 
Javascript :: How to make remove buttoon on table using js DOM 
Javascript :: await loop javascript 
Javascript :: execute command method 
Javascript :: How to add Select2 on Dynamic element - jQuery 
Javascript :: json comments 
Javascript :: regex pattern for password 
Javascript :: json stands for 
Javascript :: named regex group JS 
Javascript :: js while continue 
Javascript :: uppercase first letter javascript 
Javascript :: Javascript add leading zeroes to date 
Javascript :: TYPING TEXT USING JS 
Javascript :: Start Express Properly 
Javascript :: nextjs docs 
Javascript :: How To Add A New Element To HTML DOM 
Javascript :: js change h 
Javascript :: $.post javascript 
Javascript :: try...catch...throw javascript 
Javascript :: react hide element 
Javascript :: jest render target container is not a dom element 
ADD CONTENT
Topic
Content
Source link
Name
2+7 =