I'm currently building a small website in react native just to download a file. Can someone help me get started? I just want to download one file.
I tried using RN-Fetch-BLob but it didn't work. Can someone just tell me how to download a file?
I'm using this command:
localUri='./assets/backgroundpic.jpg'
const source=localUri = await FileSystem.downloadAsync(remoteUri, FileSystem.documentDirectory + 'background');}
Related
Im new to React Native and im using Expo to create an iOS and Android app. All I want to do is save a file that is stored in the application to the users device.
Using downloadAsync and shareAsync I can download from a remote url and save it but I can not download or just share a local file stored in in the apps directory.
Ive tried
await shareAsync('file://./manuals/mypdf.pdf');
await shareAsync('./manuals/mypdf.pdf');
await shareAsync(require('./manuals/mypdf.pdf'));
and I get the error
[Unhandled promise rejection: Error: You don't have access to provided file.] or the app just crashes
Use loadAsync to download asset data to a local file in the device's cache directory. After that the asset file is accessible like any other file.
const [{ localUri }] = await Asset.loadAsync(require('./manuals/mypdf.pdf'));
Is it possible to download/upload files and folders from FTP servers using react native? If yes, react-native-ftp package is the only one that I found which does not seem to work. Did anyone come across such a scenario?
After doing a lot of research, it seems that react-native-ftp is the only package that works, and to download, use the below code:
FTP.downloadFile(/--ftp-file-path, RNFS.ExternalStorageDirectoryPath).then((res) => {console.log("res is", res) })
FYI - RNFS.ExternalStorageDirectoryPath = This is react-native-fs to access your phone's directory and also the path where your files will be downloaded. You can view this in your phone's internal storage.
i am already try with this plugin but no luck
how to achieve like this
https://ionicframework.com/docs/native/file-opener
https://ionicframework.com/docs/native/document-viewer
Here is Ionic 5 Repo with PDF View without download
Ionic 5 With ng2-PDF-Viewer
How to run :
Clone Project
npm i
npm start
For More set PDF Options
ng2-pdf-viewer
You can also directly open the PDF by using window.open
window.open(this.URL + name +'.pdf');
It will work.
You can use PDF.js component:
https://mozilla.github.io/pdf.js/
Here is a video of PDF.js component wrapped as Appery.io plugin
https://www.youtube.com/watch?v=JeEJl7K-2H0
I am trying to implement customized direct update in ionic v3.20.0 but while accessing to the below code, am unable to proceed. I can't find any way to do it as the below function is not there in worklight.d.ts file,but can be found at worklight.js file.
The plugin used is cordova-plugin-mfp. The solution provided in the official doc is relevant to only cordova application,that can be done through index.js file which has the function WlCommonInit(). As per the doc the below code is to be called from this function, but unable to do this in ionic-cordova based application.
wl_DirectUpdateChallengeHandler.handleDirectUpdate = function(directUpdateData, directUpdateContext) {
// Implement custom Direct Update logic
};
Pleas refer to the below link for further information.
https://mobilefirstplatform.ibmcloud.com/tutorials/en/foundation/8.0/application-development/direct-update/
Please help me to implement this in ionic v3.20.0 which need to be implemented in typescript. Thanks!.
Presently there is no typescript API for wl_DirectUpdateChallengeHandler in cordova-plugin-mfp to customize direct update in Ionic Applications.
However you can do implementation in the JavaScript and include it in the Ionic Project. Following are the steps :
Create a folder called js inside the path src/assets of the project
Create a new JS file with following code and save it as wldirectudpate.js
function wlCommonInit() {
console.log(">> wlCommonInit() ..." );
wl_DirectUpdateChallengeHandler.handleDirectUpdate = function(directUpdateData, directUpdateContext) {
// Implement custom Direct Update logic
};
};
Add the JS location in index.html file which is located at /src/index.html
<script src="assets/js/wldirectudpate.js"></script>
I have a legacy Android java application into which I am integrating react native. Per Facebook's instructions, I have a generic Activity into which I have added the following code:
mReactRootView = new ReactRootView(this);
mReactInstanceManager = ReactInstanceManager.builder()
.setApplication(getApplication())
.setBundleAssetName("index.android.bundle")
.setJSMainModuleName("index.android")
.addPackage(new MainReactPackage())
.setUseDeveloperSupport(BuildConfig.DEBUG)
.setInitialLifecycleState(LifecycleState.RESUMED)
.build();
mReactRootView.startReactApplication(mReactInstanceManager, "HelloWorld", null);
setContentView(mReactRootView);
However, in my case, I have downloaded my react native bundle and placed it in my Android device's cache, so I have amended that example by adding the following call:
.setJSBundleFile(mReactNativeLocalFile.getAbsolutePath())
This has enabled me to load my downloaded bundle successfully, however none of the images load. Thus, components that load images like:
<Image source={require('./img/background.jpg')} style={styles.backgroundImage} />
Do not render an actual image.
I have confirmed that all images were successfully extracted and placed in a folder named assets adjacent to my bundle. Thus, my folder structure looks like:
com.myapp/cache/templates/MyApp/
index.android.bundle
assets/
img/
background.jpg
Thus, can anyone tell me if it is possible for a react native template bundle that has been downloaded locally to the android file system to refer to images that have also been downloaded locally to the android file system?
Based on this change, the correct answer is a folder structure on your local disk that looks like this:
com.myapp/cache/templates/MyApp/
index.android.bundle
drawable-mdpi/
img_background.jpg