A very simple file transfer example for Ionic 2 using TypeScript and the Transfer module from ionic-native.
Clone the repository and follow the steps based on the platform of your device.
Note: building iOS requires a Mac OS.
npm installionic build ios- Connect your iOS device and run the application, either by
- Opening up the relevant
.xcodeprojonXcodeand clicking the run button (making sure your device is selected) - Running
ionic run ios --deviceon your CLI - this requires that the npm packageios-deployis installed globally (npm install -g ios-deploy)
npm installionic build android- Connect your Android device and run the application with
ionic run android(make sure USB debugging is enabled on your device)
The .jpg used in this example is saved in different locations dependant on platform:
-
iOS - in the app-specific
Documents/folder usingcordova.file.documentsDirectory -
Android - persistent and private data storage within the application's sandbox using
cordova.file.dataDirectory
Here's the list of the different places you can store files using this plugin.
Using Xcode, go to Window and selected Devices, then
- Select the device you downloaded the file to
- Select the application you used to download the file (in this case
Ionic2FileTransferExample) - You should see the folder
Documents, inside of which you'll find the image.
Use adb:
adb shell
run-as com.ionicframework.ionic2filetransferexample648376
cd files
lsIonic Native has a File module (seperate from the Transfer module we're using in this example).
Using it is as simple as installing the plugin
ionic plugin add cordova-plugin-file
Importing it alongside Transfer in the home.ts
import {File, Transfer} from 'ionic-native';
Now you can get coding with it ✌🏻
MIT

