我已将 my\xc2\xa0Android 的targetSdkVersion更新为30,并且我意识到actionViewIntent函数在 Android 11 上不起作用。
\n没有抛出错误。所以我无法调试。
\n下面是我的代码:
\nRNFetchBlob.android.actionViewIntent(filePath, mimeType);\nRun Code Online (Sandbox Code Playgroud)\n更新后还有人遇到这个问题吗?请帮助我!
\n提前致谢。
\n我正在使用以下代码下载文件(可以是 PDF 或 DOC),然后使用链接打开它。
const { dirs } = RNFetchBlob.fs;
let config = {
fileCache : true,
appendExt : extension,
addAndroidDownloads : {
useDownloadManager : false,
notification : false,
title : 'File',
description : 'A file.',
path: `${dirs.DownloadDir}/file.${extension}`,
},
};
RNFetchBlob.config(config)
.fetch(
method,
remoteUrl,
APIHelpers.getDefaultHeaders()
)
.then((res) => {
let status = res.info().status;
if (status == 200) {
Linking.canOpenURL(res.path())
.then((supported) => {
if (!supported) {
alert('Can\'t handle url: ' + res.path());
} else {
Linking.openURL(res.path())
.catch((err) => alert('An error occurred …Run Code Online (Sandbox Code Playgroud) 我一直在尝试使用 React Native 和 Expo 在移动设备上保存图像,我尝试过这些软件包:
import RNFetchBlob from 'react-native-fetch-blob';
import RNfs from 'react-native-fs ';
Run Code Online (Sandbox Code Playgroud)
但在实现它们时都给了我这个错误
null is not an object (evaluating 'RNFetchBlob.DocumentDir')
Run Code Online (Sandbox Code Playgroud)
然后尝试 expo-file-system 但我没有看到任何清晰的示例来说明如何转换 base64 并将其下载到移动设备
更新
我能够做到这一点,我的目的是保存QR的base64并将其转换为png,同时能够共享它,我使用expo-file-system和做到了这一点expo-sharing
这是小米代码,
import * as FileSystem from 'expo-file-system';
import * as Sharing from 'expo-sharing';
//any image, I use it to initialize it
const image_source = 'https://images.unsplash.com/photo-1508138221679-760a23a2285b?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&w=1000&q=80';
share=()=>{
var self = this;
self.setState({loading:true})
FileSystem.downloadAsync(
image_source,
FileSystem.documentDirectory + '.png'
)
.then(({ uri }) => {
console.log(self.state.base64Code);
FileSystem.writeAsStringAsync(
uri,
self.state.base64Code,
{'encoding':FileSystem.EncodingType.Base64} …Run Code Online (Sandbox Code Playgroud) 做了什么:
在 Android 中实现并DCIM directory在 android中特定地下载它。在 ios 中DocumentDir用于下载 pdf 或 docx 文件。使用 "rn-fetch-blob": "^0.12.0";
错误:
在 IOS 中,它在控制台中显示消息:
文件保存到/var/mobile/Containers/Data/Application/E6FDC2DD-7FCA-44DC-85C4-A275078F8825/Documents/wow13.pdf
要下载的代码是这样的:
downloadFileOnSuccess = async () => {
let dirs =
Platform.OS == 'ios'
? RNFetchBlob.fs.dirs.DocumentDir
: RNFetchBlob.fs.dirs.DCIMDir;
console.log(dirs, 'document path');
RNFetchBlob.config({
// response data will be saved to this path if it has access right.
fileCache: true,
path: dirs + `/wow13.pdf`,
})
.fetch(
'GET',
'https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf',
{
//some headers ..
},
)
.then(res => { …Run Code Online (Sandbox Code Playgroud) 我已经安装react-native-fetch-blob在 react-native 上version 0.60.5。当我运行时pod install,错误出现在你可以看到的
请指导我如何解决这个问题
react-native react-native-ios react-native-fetch-blob rn-fetch-blob
async postFileUpload(payload) {
const rnfetchfile = RNFetchBlob.wrap(payload.uri);
try {
console.log(
'POST',
'https://******.***.**/******/***/upload_*******_file',
{
...this.config,
'Content-Type': 'multipart/form-data',
},
[
// element with property `filename` will be transformed into `file` in form data
{
name: 'files',
filename: payload.name,
data: rnfetchfile.replace('file://file:///', 'file://'),
},
],
);
const res = await RNFetchBlob.fetch(
'POST',
'https://******.***.**/******/***/upload_*******_file',
{
...this.config,
'Content-Type': 'multipart/form-data',
},
[
// element with property `filename` will be transformed into `file` in form data
{
name: 'files',
filename: payload.name,
data: rnfetchfile.replace('file://file:///', 'file://'),
},
],
);
const …Run Code Online (Sandbox Code Playgroud) reactjs react-native react-redux react-native-ios rn-fetch-blob
rn-fetch-blob 包包含无效配置:不允许“dependency.hooks”。请使用“react-native config”命令验证其是否正确链接,并就此联系软件包维护人员。
package.json - “react-native”:“0.69.2”,“rn-fetch-blob”:“^0.12.0”
react-native ×8
android ×2
expo ×2
ios ×2
dependencies ×1
fetch ×1
react-hooks ×1
react-redux ×1
reactjs ×1