我有一个angular8
应用程序,我想在服务器上发送文件。我正在使用ng2-file-upload
.
这是我的 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);
}
在component.html
我有这个
<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)">
现在http
post
,当我选择任何文件时,请求它不在网络选项卡中发送。它只打印正在onFileSelected
运行的控制台。它打印文件对象。
我究竟做错了什么?