首页 > 解决方案 > multipartfile 可以用图像发送一些信息吗?

问题描述

我想用一些信息将 multipart/form-data 发送到 spring 服务器。但我不知道这是正确的方法。

a.push({ name: 'file', filename: this.state.fileName, data: RNFetchBlob.wrap(this.state.uri), desc: 'triptriptrip'});
this.setState({
    images : a
  })
  });}

RNFetchBlob.fetch('POST',  'https://675c8a26.ngrok.io/appServer/postUpload/1', {
            'Content-Type': 'multipart/form-data',
        },this.state.images

        )

我希望 spring 服务器获得“desc”信息,但服务器无法访问“desc”。如何访问该数据?

标签: springreact-native

解决方案


如果要使用formdata,请像这样使用它。

RNFetchBlob.fetch('POST','https://675c8a26.ngrok.io/appServer/postUpload/1',{
    'Accept': 'application/json',
    'Content-Type': 'multipart/form-data',
  },
  [
  { name: 'file', filename: this.state.fileName, data: RNFetchBlob.wrap(this.state.uri), desc: 'triptriptrip'},
  ]).then((response) => response.json())
    .then((res) => {
      console.log(res);
  }).catch(err => {
    console.log(err)
  })  
});

推荐阅读