Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

angular file upload code anji

import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';

@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {

    uploadedFiles: Array < File > ;

    constructor(private http: HttpClient) {

    }

    ngOnInit() {

    }

    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

PREVIOUS NEXT
Code Example
Javascript :: How many options are there to climb a ladder with N 
Javascript :: iconbuttons onclick redirect to another page on react 
Javascript :: A Note on Jest & React 
Javascript :: site:stackoverflow.com how to see all react dependencies 
Javascript :: how to add picture to picture video js in old library in js 
Javascript :: Solution-2--solution options for reverse bits algorithm js 
Javascript :: how to run json server 
Javascript :: jquery try catch 
Javascript :: get selected data items kendo grid 
Javascript :: jsdoc default value 
Javascript :: editor convert jquery code to javascript 
Javascript :: npm ERR! This is probably not a problem with npm. There is likely additional logging output above. 
Javascript :: dom traversal jquery 
Javascript :: js DFS 
Javascript :: 206. reverse linked list javascript 
Javascript :: fill array with array javascript 
Javascript :: react upload image 
Javascript :: JavaScript (SMonkey 60.2.3) sample 
Javascript :: user authentication and routing + nodejs + express 
Javascript :: inappbrowser hide url 
Javascript :: ternary operator multiple conditions 
Javascript :: Export Multiple Objects 
Javascript :: date methods javascript 
Javascript :: js console.log callstack 
Javascript :: nodejs: Basic: managing file: Read, Write, Create, Delete 
Javascript :: Create & Download PDF from Byte[] Array using jQuery AJAX 
Javascript :: Disemvowel Trolls 
Javascript :: phaser animation on repeat event 
Javascript :: core.mjs:4057 JIT compilation failed for NgModule class AppModule 
Javascript :: React "Nothing was returned from render Error" Solution 
ADD CONTENT
Topic
Content
Source link
Name
6+1 =