Upload the file from the server to the Ionic2 app
I need to implement a function in my application Ionic2
where users can upload a specific video file to the Ionic2 application.
After checking the section, Ionic Native
I found the following plugins are available:
- File
- File selection
- File opener
- The path to the file
But couldn't find anything like ' cordova-plugin-file-transfer ' where a specific DOWNLOAD method exists .
What could be the way out?
Please suggest.
source to share
You can use Transfer's own plugin for this.
This plugin allows you to upload and download files.
ionic plugin add cordova-plugin-file-transfer
npm install --save @ionic-native/transfer
source to share
You must use the " Transfer " plugin to load the file in ionic2
You can install the plugin using this command
ionic plugin add cordova-plugin-file-transfer
npm install --save @ionic-native/transfer
and then import it
import { Transfer, FileUploadOptions, TransferObject } from '@ionic-native/transfer';
install constructor
constructor(private transfer: Transfer, private file: File) { }
Then use this function to download file using url
download() {
const url = 'http://www.example.com/file.pdf';
fileTransfer.download(url, this.file.dataDirectory +
'file.pdf').then((entry) => {
console.log('download complete: ' + entry.toURL());
}, (error) => {
// handle error
});
}
Hope this helps you You can also upload the file using this plugin
source to share