我想在需要一个
File
在键上键入对象
file
.
前端成角,所以流动
TS
const _file: File = __userAvatar.files[0];
const _userAvatarInfo = { userId: this.user.id, avatar: _file };
this.userService.updateUserAvatar(_userAvatarInfo).subscribe(
用户服务.ts
const _formData = new FormData();
_formData.append("avatar", _userAvatarInfo.avatar);
_formData.append("userId", _userAvatarInfo.userId);
return this.http.post(`${this.context}/userservice/user/updateuseravatar`, _formData);
节点api层使用
giuseppe
@Post("/user/updateuseravatar")
updateUserAvatar(@Req() req: any): Promise<any> {
return TrusteeFacade.uploadResource({ resourceId: "some_id", resource: req.files.avatar });
}
外墙层
static uploadResource(__resourceInfo: any): Promise<any> {
const _resourceData = new FormData();
_resourceData.append("mimetype", "image/png");
_resourceData.append("file", __resourceInfo.resource);
// this will not get printed
console.log("From**************", __resourceInfo.resource);
return axios({
method: "post",
url: `${process.env.REST_URL}/resources/${__resourceInfo.resourceId}`,
headers: _resourceData.getHeaders(),
data: _resourceData
});
}
在正立面层
TypeError: source.on is not a function
at Function.DelayedStream.create (D:\QPP Workspace\ContentPlatform\webapplications\application-services\node_modules\delayed-stream\lib\delayed_stream.js:33:10)
at FormData.CombinedStream.append (D:\QPP Workspace\ContentPlatform\webapplications\application-services\node_modules\combined-stream\lib\combined_stream.js:44:37)
at FormData.append (D:\QPP Workspace\ContentPlatform\webapplications\application-services\node_modules\form-data\lib\form_data.js:74:3)
at Function.uploadResource (D:\QPP Workspace\ContentPlatform\webapplications\application-services\.bin\facade\trustee-facade.js:221:23)
at trustee_facade_1.TrusteeFacade.getFileResourceId.then (D:\QPP Workspace\ContentPlatform\webapplications\application-services\.bin\api\user-service.js:118:51)
at propagateAslWrapper (D:\QPP Workspace\ContentPlatform\webapplications\application-services\node_modules\async-l
这个
__resourceInfo
在门面层有正确的信息,但是创建
FormData
这就是错误的原因?