I have an angular8
app in which i want to send file on server.I am using ng2-file-upload
.
Here is my component.ts
import { FileUploader, FileLikeObject } from 'ng2-file-upload';
const URL = `${environment.api_base_url}/files`;
public uploader: FileUploader = new FileUploader({
url: URL,
disableMultipart : false,
autoUpload: true,
method: 'post',
itemAlias: 'file',
allowedFileType: ['pdf', 'csv']
});
public onFileSelected(event: EventEmitter<File[]>) {
const file: File = event[0];
console.log(file);
}
In component.html
i have this
<button class="btn btn-primary btn-submit btn-block mb-1" (click)="fileInput.click()">Upload Customer CSV</button>
<input type="file" class="d-none" id="csvFileUpload" #fileInput ng2FileSelect [uploader]="uploader" (onFileSelected)="onFileSelected($event)">
Now http
post
request it is not sending in network tab when i select any file. It only prints console that is in onFileSelected
function. It prints file object.
What am i doing wrong?