试图在Ionic 2中上传FileTransfer图像和用户数据?

时间:2017-09-07 12:51:00

标签: javascript ionic-framework ionic-native

我正在尝试发送到我的端点,用户图像以及所有用户数据。我从设备库中获取用户图像,它有这条路径:

let imageLocation = file:///data/user/0/.../cache/tmp_IMG-20170907-WA0026534743393.jpg;

然后我有了用户对象:

this.dataUser = {
    name: "jhon",
    email: "jhon@live.com",
    id: 123
};

现在我创建了TransferObject对象并实现了上传功能:

const fileTransfer: TransferObject = this.transfer.create();
let options: FileUploadOptions = {
    fileKey: 'avatar',
    httpMethod: 'PUT',
    headers: { 'Authorization': 'JWT ' + token },
    params: this.dataUser
}

return new Promise(resolve => {
  fileTransfer.upload(imageLocation, URL, options, true)
              .then((data) => {
                console.log('upload success -> ', data);
                resolve(data);                 
              }, error => {
                console.log(error);
              });
});

当执行该功能时,上传似乎成功,因为它返回 responseCode = 200 的对象,但响应键保持空字符串,为什么?

这是我的上传输出:

{bytesSent: 488723, responseCode: 200, response: "{"avatar": null, "name": "", "email": "", "id": null}"}

0 个答案:

没有答案