对本机获取blob多图像上传与其他数据做出反应

时间:2018-12-06 13:09:13

标签: react-native react-native-fetch-blob

我想将多张带有其他一些信息的图像发送到后端, 我可以发送多个图像,但是当我尝试添加一些其他信息时,出现xcode错误

 uploadFile = () => {
    console.log('upload');
    console.log(this.state.images);
    RNFetchBlob.fetch('POST', 'http://127.0.0.1:8000/api/addProduct',
        {
            otherHeader : "foo",
            'Content-Type': 'multipart/form-data'
        },

          [
              this.state.images.map( i => ({
                  name: 'image[]' ,
                  filename: i.filename || i.path.split('/').slice(-1)[0], // filename sadece ios da var, o yüzden android de path dan çıkarıyoruz
                  type: i.mime,
                  data: RNFetchBlob.wrap(i.path)
              })),
          ]

    ).then(res=>{console.log(res)})
}

它像那样工作,但是当我尝试添加更多信息时不起作用。

    uploadFile = () => {
    console.log('upload');
    console.log(this.state.images);
    RNFetchBlob.fetch('POST', 'http://127.0.0.1:8000/api/addProduct',
        {
            otherHeader : "foo",
            'Content-Type': 'multipart/form-data'
        },

          [
              this.state.images.map( i => ([
                  {
                      name: 'image[]' ,
                      filename: i.filename || i.path.split('/').slice(-1)[0], // filename sadece ios da var, o yüzden android de path dan çıkarıyoruz
                      type: i.mime,
                      data: RNFetchBlob.wrap(i.path)
                  },
                  {name:'productName' ,data:this.state.title}
              ])),
          ]

    ).then(res=>{console.log(res)})
}

}

0 个答案:

没有答案