我正在使用react-native-fs,我正在尝试将pdf文件的base64保存到我的android模拟器文件系统中.
我从服务器收到base64编码的pdf.
然后我用行解码base64字符串:
var pdfBase64 = 'data:application/pdf;base64,'+base64Str;
Run Code Online (Sandbox Code Playgroud)
saveFile()函数
saveFile(filename, pdfBase64){
// create a path you want to write to
var path = RNFS.DocumentDirectoryPath + '/' + filename;
// write the file
RNFS.writeFile(path, base64Image, 'base64').then((success) => {
console.log('FILE WRITTEN!');
})
.catch((err) => {
console.log("SaveFile()", err.message);
});
}
Run Code Online (Sandbox Code Playgroud)
错误
当我尝试保存pdfBase64时,saveFile()函数捕获以下错误:
bad base-64
Run Code Online (Sandbox Code Playgroud)
问题
任何人都可以告诉我哪里或者我做错了什么?谢谢.
我想用uri填充图像。
我从服务器请求图像,它返回一个BLOB。
然后,我将BLOB转换为带有以下行的URL:
var blobUrl = URL.createObjectURL(blob);
Run Code Online (Sandbox Code Playgroud)
然后,我尝试用URL填充图像:
<Image source={{uri: blobURL}} style={{width: 100, height: 50}} />
Run Code Online (Sandbox Code Playgroud)
图像将不会显示。我该怎么办?
我正在使用连接到本地主机的android模拟器。可能与BLOB url被存储到本地主机有关吗?
还是可能是简单的语法错误?
谢谢。
javascript blob android-emulator react-native react-native-android
我是反应原生的新手.我在https://facebook.github.io/react-native/docs/sample-application-movies.html中看到了一个例子.它正在构建一个电影应用程序,可以获取电影并在ListView中显示它们.我们如何选择一行来获取其详细数据并在其他视图中显示?请帮忙.谢谢 :)
这是我到目前为止所做的:
/**
* Sample React Native App
* https://github.com/facebook/react-native
*/
import React, {
Component,
} from 'react';
import {
AppRegistry,
Image,
ListView,
StyleSheet,
Text,
View,
Navigator,
TouchableOpacity,
} from 'react-native';
var REQUEST_URL = 'https://raw.githubusercontent.com/facebook/react-native/master/docs/MoviesExample.json';
var SCREEN_WIDTH = require('Dimensions').get('window').width;
var BaseConfig = Navigator.SceneConfigs.FloatFromRight;
var CustomLeftToRightGesture = Object.assign({}, BaseConfig.gestures.pop, {
snapVelocity: 8,
edgeHitWidth: SCREEN_WIDTH,
});
var CustomSceneConfig = Object.assign({}, BaseConfig, {
springTension: 100,
springFriction: 1,
gestures: {
pop: CustomLeftToRightGesture,
}
});
var PageOne = React.createClass({
getInitialState:function(){
return{
dataSource: …Run Code Online (Sandbox Code Playgroud)react-native react-native-listview react-native-android react-native-ios
是否可以将图像保存到Android的本地文件系统,以便可以从手机的"图库"和文件夹中查看?
我找到了这个react-native-fs库,但在研究了文档并通过一个例子后,我仍然不确定它是否可行.
谢谢
filesystems react-native react-native-android react-native-fs react-native-fetch-blob
经过大量研究后,我发现Android的Dimensions库不能像预期的那样工作.例如,每次我使用"Dimensions.get('window').height"时,我会得到不同的结果.
这是在git:
Dimensions.get('window')上记录的.在Android上,高度有时是错误的
解决方案是使用上面git链接中提到的"getRealDimensions"库.
这是'getRealDimensions'的链接,但它是用java编写的,我不知道如何将它实现到我的react-native android项目中.
总结
如何在我的react-native android项目中实现'getRealDimensions'库?
谢谢.
我正在使用react-native-fetch-blob库中的文件系统API。
我从服务器请求图像,接收 Base64,然后将其保存到 android fs 中的 Pictures 目录。
我这样保存图像:
var RNFetchBlob = require('react-native-fetch-blob').default;
const PictureDir = RNFetchBlob.fs.dirs.PictureDir;
getImageAttachment: function(uri_attachment, filename_attachment, mimetype_attachment) {
return new Promise((RESOLVE, REJECT) => {
// Fetch attachment
RNFetchBlob.fetch('GET', config.apiRoot+'/app/'+uri_attachment)
.then((response) => {
let base64Str = response.data;
let imageLocation = PictureDir+'/'+filename_attachment;
//Save image
fs.writeFile(imageLocation, base64Str, 'base64');
console.log("FILE CREATED!!")
}).catch((error) => {
// error handling
console.log("Error:", error)
});
},
Run Code Online (Sandbox Code Playgroud)
问题
图像保存成功,但当我打开 Android 的图库时,它不可见。但是当我关闭并打开 Android 模拟器时,它就会在图库中可见。
问题
如何在不重启模拟器的情况下查看Android图库中的图片?
创建文件后,我将其添加到上述方法中:
RNFetchBlob.fs.scanFile([ { path : imageLocation, …Run Code Online (Sandbox Code Playgroud) react-native ×6
android ×1
autoconf ×1
automake ×1
base64 ×1
blob ×1
filesystems ×1
image ×1
javascript ×1
libtool ×1
macos ×1
watchman ×1