react-native-fs

React-native packager configuration - How to include .zip file in bundle?

自作多情 提交于 2019-12-11 17:46:55
问题 My problem: I have a zip file that contains a firmware update for my company's device I want to be able to access it using react-native-fs with the code below . export function readAssetFile(name) { if(Platform.OS === 'ios') { return RNFS.readFile(`${RNFS.MainBundlePath}/assets/data/${name}`); } else { return RNFS.readFileAssets(`raw/${name}`, 'base64'); } } My project structure looks like: ProjectDir android data image1.png image2.png firmwarefile.zip ios The android branch works, because I

How to access files and folders using react-native-fs library

笑着哭i 提交于 2019-12-11 05:07:01
问题 I am using react-native-fs for file system access. However am unable to access files in ios. Below is the code: RNFS.readDir(RNFS.MainBundlePath) .then((result) => { console.log('Got result', result); return Promise.all([RNFS.stat(result[0].path), result[0].path]); }) .then((statResult) => { console.log('stat result',statResult); if(statResult[0].isFile()){ return RNFS.readFile(statResult[1], 'utf8'); } return 'no file'; }) .then((contents) => { console.log('Got Contents',contents); }) .catch

React-Native: How to open locally bundled binary file

一曲冷凌霜 提交于 2019-12-10 18:27:22
问题 I'm writing a react-native app, and I want it to deploy with a zip file that contains a device firmware update. Before letting the user send the update, I need my code to open the zip and do some validation of its contents. I've found lots of zip-handling NPM packages, so all I need to do is load the file contents so I can feed it to one of these. require('./firmware/fw.zip'); <-- packager doesn't include .zip by default require('./firmware/fw.pdf'); <-- [gross hack] packager includes pdfs,

react-native-fs: How to read local images (Get base64 of local file)

不问归期 提交于 2019-12-08 12:23:14
问题 I have local files in my app which I read like this: <Image source={require("../../img/pic1.jpg") /> How to read this file using RNFS.readFile(filepath, "base64"); using RNFS.readFile("../../img/pic1.jpg", "base64"); gives me error "no such file" 回答1: react-native-fs will only access the files from device storage. So this problem poses a quandary. These files are bundled at build time so how can we access them in development vs production? My project structure ├── android ├── app │ └── assets

How to download a file with React Native?

只谈情不闲聊 提交于 2019-11-28 19:25:41
I am building an app with React Native, for Android and iOS. I am trying to let the user download a PDF file when clicking on a button. react-native-file-download does not support Android react-native-fs does nothing when I trigger downloadFile (nothing shows up on the notification bar), and I am not able to find the file after that. I added android.permission.WRITE_EXTERNAL_STORAGE to the Android Manifest file. I double-checked that the file I am trying to download exists (when it does not, the library throws an error) I do not find other solutions for this problem. I have found libraries for

How to download a file with React Native?

梦想的初衷 提交于 2019-11-27 12:15:13
问题 I am building an app with React Native, for Android and iOS. I am trying to let the user download a PDF file when clicking on a button. react-native-file-download does not support Android react-native-fs does nothing when I trigger downloadFile (nothing shows up on the notification bar), and I am not able to find the file after that. I added android.permission.WRITE_EXTERNAL_STORAGE to the Android Manifest file. I double-checked that the file I am trying to download exists (when it does not,

How to save pdf to android file system and then view PDF - react-native

狂风中的少年 提交于 2019-11-27 01:25:22
问题 I am using the react-native-fs and I am trying to save a base64 of a pdf file to my android emulators file system. I receive base64 encoded pdf from the server. I then decode the base64 string with the line: var pdfBase64 = 'data:application/pdf;base64,'+base64Str; saveFile() function 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) => {