如何在Multipart superagent请求中发送一个Object和一个附加文件?

我正在尝试使用superagent对我的API进行多部分POST请求。

我的代码:

superagent .post(apiUrl + '/api/company/profile/edit') .field("profileData", profileData) .attach('company_logo', logoFile ) .set('Accept', 'application/json') .end(function(err, res){ if(err){ dispatch(updateProfileStatusAction("error", res)); } else { dispatch(updateProfileStatusAction("success", res)); } }); 

我遇到的问题是profileData是一个嵌套的对象。 当我在API中获取请求时,我将profileData的值看作string[Object, Object]

当我查看多部分请求的文档,使用superagent https://visionmedia.github.io/superagent/#multipart-requests时,它看起来像.field()只是一个键,值对而不是一个对象。 然后我尝试使用.send({profileData:profileData})而不是字段,但是当我这样做时,我得到一个错误,说.attach和.send不能在同一个请求中一起使用。

我认为它应该足以使用JSON.stringify()将JS_Object转换为JSONstring。

 superagent .post(apiUrl + '/api/company/profile/edit') .field("profileData", JSON.stringify(profileData)) .attach('company_logo', logoFile ) ...