when i try to upload zip file then unfortunately it doesn\'t get uploaded on the server. It gives me error something went!!! Here is my code:
const event = t
you could use something like that:
<input type="file" formControlName="uploadFile" (change)="uploadFileToServer($event)"/>
import { Component } from '@angular/core';
import { RequestOptions, Headers, Http } from '@angular/http';
@Component({
selector: 'file-uploader',
templateUrl: './uploadFile.component.html',
styleUrls: ['./uploadFile.component.css'],
})
export class FileUploadComponent {
public uploadFileToServer(event) {
let fileList: FileList = event.target.files;
if (fileList.length > 0) {
let file: File = fileList[0];
let formData: FormData = new FormData();
formData.append('uploadFile', file, file.name);
formData.append('fileType', 'zip');
let headers = new Headers();
headers.append('Accept', 'application/json');
let options = new RequestOptions({ headers: headers });
this.http.post('your url here', formData, options)
.map(res => res.json())
.catch(error => Observable.throw(error))
.subscribe(
data => console.log('success'),
error => console.log(error)
)
}
}
}