首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用rn-fetch-blob和POST下载文件

使用rn-fetch-blob和POST下载文件
EN

Stack Overflow用户
提问于 2019-02-06 21:09:54
回答 2查看 2.7K关注 0票数 0

我使用的是rn-fetch-blob,如何下载需要通过POST在请求体中传递一些参数的文件?我试过了:

代码语言:javascript
复制
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没有收到我在请求体上传递的数据

EN

回答 2

Stack Overflow用户

发布于 2019-02-06 21:57:49

你基本上没有在你的请求中附加正文:

代码语言:javascript
复制
fetch(method, url, headers, body)

查看此处:https://github.com/joltup/rn-fetch-blob/wiki/Fetch-API

票数 0
EN

Stack Overflow用户

发布于 2019-05-03 18:52:20

代码语言:javascript
复制
var tempParam = [{name: 'image',filename: 'image.jpg',data: RNFetchBlob.wrap(uri}]

name是关键。如果您向API发送文件,则需要使用filename。包装文件数据的方法可以在fetch API上找到(如果我没有错的话)

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54554436

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档