最终用户应该通过文件浏览器上传一个 excel 文件:
<FloatingActionButton title="Upload excel" primary className="import-vendor"
containerElement="label"
label="Browse file">
<input onChange={(e) => Actions.uploadXLS(e.target.files[0])}
type="file"
name="xls"
accept="application/vnd.ms-excel"
style={{ display: 'none' }}/>
<UploadIcon/>
</FloatingActionButton>
行动 :
uploadXLS(file) {
this.getInstance().callUploadXLS( file );
}
服务 :
callUploadXLS: {
remote( state, data ) {
const url = `${base}/vendor/form`;
return $http.instance.api.post( url, data );
},
success: Actions.XLSUploaded,
error: Actions.fail
}
此文件应发送到使用 Spring Boot 构建的 POST REST 端点,该端点接受多部分文件。端点无法识别这样发送文件
error: "Internal Server Error"
exception :"org.springframework.web.multipart.MultipartException"
message : "Current request is not a multipart request"
path : "/vendor/form"
status : 500
timestamp : 1501747384079
我如何发布excel文件?
编辑:我现在正在尝试发布文件列表:
const arrayOfFile = [];
let i = 0;
for ( i = 0; i < files.length; i++ ) {
const data = new FormData();
arrayOfFile[i] = data.append( 'file', files[i] );
}
this.getInstance().callUploadXLS( arrayOfFile );
但是 data.append('file', files[i]); 总是不确定地返回