我正在MEAN STACK中构建一个产品,该产品需要通过angular上传一个csv格式文件,并将其传递给node js以异步读取完整的文件... 但有些我如何无法获取formdata.append起作用 下面给出的是我的完整代码
<input type="file" name="file" (change)="UploadFile($event.target.files)" />
<button class="btn btn-danger btn-round" (click)="SendUploadFile()" [disabled]="disable_upload">
<i class="material-icons">cloud_upload</i> Upload</button>
我的component.ts文件
UploadFile(files: FileList)
{
this.fileToUpload = files.item(0);
if(this.fileToUpload!=null)
{
this.disable_upload=false;
}
}
SendUploadFile()
{
if(this.fileToUpload!=null)
{
this.disable_upload=false;
this.cis.fileUpload(this.fileToUpload,this.selected_company_name).subscribe(res=>{
});
}
}
我的cis.service.ts文件是
fileUpload(fileToUpload,company_name)
{
const formData: FormData = new FormData();
formData.append('file', fileToUpload, fileToUpload.name);
return this.http.post('http://localhost:8000/cids/read_file',formData,
{reportProgress:true});
}