问题
I'm use rn-fetch-blob, how can I download the file where I need to pass some parameters in the body of the request with POST? I've tried this:
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 })
})
But the API don't receive the data that I pass on body of request
回答1:
You basically didn't attach a body to your request:
fetch(method, url, headers, body)
See here: https://github.com/joltup/rn-fetch-blob/wiki/Fetch-API
回答2:
var tempParam = [{name: 'image',filename: 'image.jpg',data: RNFetchBlob.wrap(uri}]
name
is the key. filename
is required if you send a file to API. The method to wrap data of file can be found at fetch API (if im not wrong)
来源:https://stackoverflow.com/questions/54554436/download-file-with-rn-fetch-blob-with-post