Download file with rn-fetch-blob with POST

家住魔仙堡 提交于 2020-01-07 14:43:28

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!