Ionic 2 File Transfer Example
A very simple file transfer example for Ionic 2 using TypeScript and the Transfer module from ionic-native
.
Build
Clone the repository and follow the steps based on the platform of your device.
iOS
Note: building iOS requires a Mac OS.
npm install
ionic build ios
- Connect your iOS device and run the application, either by
- Opening up the relevant
.xcodeproj
onXcode
and clicking the run button (making sure your device is selected) - Running
ionic run ios --device
on your CLI - this requires that the npm packageios-deploy
is installed globally (npm install -g ios-deploy
)
Android
npm install
ionic build android
- Connect your Android device and run the application with
ionic run android
(make sure USB debugging is enabled on your device)
File Transfer - Storage Locations
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.
Testing
iOS
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.
Android
Use adb
:
adb shell
run-as com.ionicframework.ionic2filetransferexample648376
cd files
ls
Extending this example - checking if files/directories exist, copying files etc.
Ionic 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 ✌🏻
License
MIT