angular - 单击提交按钮无法将我的文件发布或提交到服务器
问题描述
单击提交按钮后,我想发布一个 csv 文件。但是,在单击提交按钮时,它会给出错误,指出所选文件未作为请求添加到 post 命令中。请帮忙。以下是我选择文件并将文件提交到服务器的功能的代码片段
fileChangeListener($event) {
var text = [];
var files = $event.target.files;
if (appConstants.validateHeaderAndRecordLengthFlag) {
if (!this.appService.isCSVFile(files[0])) {
this.errorMessage = "Please import valid .csv file.";
this.isFail = true;
this.fileReset();
return;
}
}
var input = $event.target;
let url = "/uploadInspectionReport";
let token = this.appService.getToken();
if (token) {
console.log("file getting", input.files[0])
this.gettingFile = input.files[0]
this.buttonStatus = false
} (err) => {
console.log("******** Error in uploading inspection records: *********");
console.log(err);
this.errorMessage = err;
this.isFail = true;
}
}
submitFile(File) {
//this.confirmationDialogService.confirm('Please confirm..', 'Do you really want to ... ?')
//.then((confirmed) => console.log('User confirmed:', confirmed))
//.catch(() => console.log('User dismissed the dialog (e.g., by using ESC, clicking the cross icon, or clicking outside the dialog)'));
let url = "/uploadInspectionReport";
let token = this.appService.getToken();
if (token) {
this.appService
.postCsv(url, token, File)
.subscribe(
result => {
console.log("******** Uploaded inspection records *********");
this.isFileUploaded = true;
this.csvUploadMessage = result.statusMessage;
}
);
} (err) => {
console.log("******** Error in uploading inspection records: *********");
console.log(err);
this.errorMessage = err;
this.isFail = true;
}
}
解决方案
推荐阅读
- python - 行之间相对于列字段的总时间差(以毫秒为单位)
- c# - 现有 ASP .Net Webform App - 如何添加专用客户端登录
- javascript - 使用asp.net显示警报消息后重定向到弹出窗口?
- autohotkey - 如果程序已打开,请将其关闭
- javascript - 后处理程序无法正常工作-React Native
- kendo-grid - 如何判断哪个剑道网格动作触发了数据源更改事件?
- reactjs - Redux-Saga:API 调用完成后更改 url
- android - 初始加载后更新 PagedListAdapter 以显示最新的网络数据
- javascript - 如何防止 Pinterest 保存按钮“隐藏”在 div 下?
- node.js - 发生 Firebase 身份验证错误