我使用的是rn-fetch-blob,如何在需要使用POST在请求正文中传递一些参数的位置下载文件?我已经尝试过了:
RNFetchBlob
.config({
// add this option that makes response data to be stored as a file,
// this is much more performant.
fileCache: true,
path: RNFetchBlob.fs.dirs.DownloadDir + '/video.mp4'
})
.fetch('POST', `${SERVER}/get_video`, {
unique_key: TerminalID(),
id_midia: '2'
})
.then((res) => {
// the temp file path
Alert.alert('Caminho', 'The file saved to ' + res.path())
this.setState({ download: true, downloadActionFinished: true })
})
但是API没有收到我在请求正文中传递的数据
答案 0 :(得分:0)
您基本上没有在请求中附加正文:
fetch(method, url, headers, body)
答案 1 :(得分:0)
var tempParam = [{name: 'image',filename: 'image.jpg',data: RNFetchBlob.wrap(uri}]
name
是关键。如果您将文件发送到API,则需要filename
。可以在fetch API中找到包装文件数据的方法(如果我没记错的话)