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

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 :: promise catch javascript 
Javascript :: underline unused code vscode 
Javascript :: emergency food meme 
Javascript :: robot js click 
Javascript :: opacity material ui 
Javascript :: react inlinle style set background image 
Javascript :: emergency food 
Javascript :: json schema example 
Javascript :: javascript get first entry from set 
Javascript :: joi not empty string 
Javascript :: splice javascript 
Javascript :: Javascript swap old and new method 
Javascript :: Create A React State 
Javascript :: how to remove letters from an array javascript 
Javascript :: how to create a json server 
Javascript :: ja display snippet from text string 
Javascript :: react hooks in codepen 
Javascript :: vue.js props undefined type 
Javascript :: version check 
Javascript :: phaser create animation from sprite sheet 
Javascript :: google scripts string split 
Javascript :: javascript count occurence of character in string 
Javascript :: ./node_modules/react-draft-wysiwyg/dist/react-draft-wysiwyg.js 
Javascript :: javascript if 
Javascript :: how to send dm to every member in discord with discord.js 
Javascript :: How to get a range numbers from given numbers in javascript 
Javascript :: sort array ij js 
Javascript :: having written a counter with redux how does it work 
Javascript :: comparing html text by using jquery 
Javascript :: update object within object by id js 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =