1. 基于MEAN的技术栈,使用restful风格的接口
2. 在前端代码中放置文件上传按钮和处理表单数据
<div class="upload-file btn btn-sm btn-primary mb-2"> <span><i class="fa fa-upload"></i> Upload</span> <input type="file" class="btn btn-sm btn-primary mb-2" (change)="fileChange($event, topic)" placeholder="Upload file" accept=".csv,.xls"> </div>
处理上传文件,生成表单数据
fileChange(event, topic) { this.topic = topic; const fileList: FileList = event.target.files; const file: File = fileList[0]; const formData: FormData = new FormData(); formData.append('_id', topic._id); formData.append('file', file, file.name); this.topicService.uploadMark(formData).