gpt4 book ai didi

react-native - 使用 RN-FETCH-BLOB 下载 mp3 文件

转载 作者:行者123 更新时间:2023-12-04 10:34:29 29 4
gpt4 key购买 nike

我正在尝试从链接下载带有 rn-fetch-blob 的 ios 中的 mp3 文件
https://www.myinstants.com/media/sounds/anime-wow-sound-effect-mp3cut.mp3 .我将与 react-native-share 共享此文件,但我无法检索正确的文件,就像它不是 mp3 文件一样。这是whatsapp无法打开的文件。

RNFetchBlob
.config({
fileCache: true,
appendExt : 'mp3'
})
.fetch('GET', url, {
//some headers ..
})
.then((res) => {
// the temp file path
console.log('The file saved to ', res.path())
const shareOptions = {
title: 'Share via',
message: 'Do not miss to share meme sounds',
url: 'file://' + res.path(),
};
Share.share(shareOptions)
.then((res) => console.log(res))
.catch((err) => err && console.log(err))
})

下载的文件返回这样的路径 /var/mobile/Containers/Data/Application/BC8BC14B-FE8B-4E2C-ACA4-799270D8972B/Documents/RNFetchBlob_tmp/RNFetchBlobTmp_m6vz8itit4jxuxpb8tabrm

如果我添加 appendExt: 'mp3'它返回这样的东西 /var/mobile/Containers/Data/Application/BC8BC14B-FE8B-4E2C-ACA4-799270D8972B/Documents/RNFetchBlob_tmp/RNFetchBlobTmp_m6vz8itit4jxuxpb8tabrm.mp3

如果我在 whatapp 上分享它,我会得到这些文件之类的东西。这不是 mp3 文件。这甚至不是我无法打开的文件。问题是我在ios中以正确的方式下载mp3文件吗?如果我这样做,为什么我看不到以 .mp3 扩展名结尾的路径?或者我只是以错误的方式使用共享库,请有人启发我。
enter image description here

enter image description here

最佳答案

我解决了这个问题。 RN-Fetch-Blob 路径在 iOS 中并不是很好。最好像这样指定路径。
let path = RNFetchBlob.fs.dirs.DocumentDir
并像这样在 RNFetchBlob.config 中的路径末尾传递要下载的文件。

 RNFetchBlob
.config({
fileCache: true,
path: path + '/sound.mp3',

})

如果您想将文件共享到随机应用程序。使用 react-native-share 库的 网址 像这样的参数。
const shareOptions = {
subject: 'Music',
title: '',
message: 'Do not miss to share meme sounds',
url: res.path(),
};

两者 url: 'file:// + res.path()url: res.path()将在 Android 中正常工作。但在我的情况下,声明 url 没有 file://正在工作。

关于react-native - 使用 RN-FETCH-BLOB 下载 mp3 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60253650/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com