根据后端,我需要通过post请求传递3个参数,这个后端函数是:
public ResponseModel Post([FromBody] CourseFileUpload item, string fileName, Stream fileToUpload) 现在我试着像这样传递这个参数:
uploadFile(uploadData:ModelToFileSteam):Observable<ModelToFileSteam> {
const fileName = uploadData.fileName;
console.log('file name is', fileName);
const headers = new HttpHeaders({ 'Content-Type': 'application/json', 'Access-Control-Allow-Origin':'*' });
return this.http.post<ModelToFileSteam>(environment.baseUrl+`CourseFileUpload`, uploadData.fileToUpload, uploadData.fileName, uploadData.uploadStream)
.pipe(
map(data => {
return data;
} ),
catchError(this.handleError)
)
}但是得到了错误,根本不能传递3个参数。做这件事的正确方法是什么?
有人帮我吗?
发布于 2019-03-26 13:12:45
我建议将所有内容包装在一个对象中。并发送到后台。
或者直接发送uploadData
return this.http.post<ModelToFileSteam>(environment.baseUrl+`CourseFileUpload`, uploadData)
.pipe(
map(data => {
return data;
} ),
catchError(this.handleError)
)在后端,你可以像req.body.uploadData一样让uploadDate检查你可以console.log(uploadData.fileName);
发布于 2019-03-25 16:08:04
这是我的工作示例
this.http.post<Customer>(this.base_url + 'v1/customers', client, this.getHeaders());其中client是customer对象,this.getHeaders()是:
getHeaders() {
return {
headers: new HttpHeaders({
'Content-Type': 'application/json; charset=utf-8',
})
};
}祝你好运!
https://stackoverflow.com/questions/55332958
复制相似问题