Alice
Alice

Reputation: 701

Uploading images using form ionic

I have a website that has a form and users can upload one image before submitting the form.

I am trying to do the same thing with Ionic framework.

What I have done so far:

Installed ngCordova Steps

Added plugins:

cordova plugin add cordova-plugin-file
cordova plugin add cordova-plugin-file-transfer

And here is my run:

angular.module('starter', ['ionic', 'starter.controllers', 'ngCordova'])

    .run(function ($ionicPlatform) {
        $ionicPlatform.ready(function () {
            // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
            // for form inputs)
            console.log(FileTransfer);
            if (window.cordova && window.cordova.plugins.Keyboard) {
                cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
                cordova.plugins.Keyboard.disableScroll(true);

            }
            if (window.StatusBar) {
                // org.apache.cordova.statusbar required
                StatusBar.styleDefault();
            }
        });
    })

Console prints out:

Uncaught ReferenceError: FileTransfer is not defined

I'm stuck here, I tried an example controller but it did not work. I am using ionic serve -l to test this, and ionic View on my iPhone. Anyone has any idea why or how to fix this? Thanks!

Upvotes: 0

Views: 131

Answers (1)

liuwenzhuang
liuwenzhuang

Reputation: 966

Your steps are correct, just test in emulator or real device rather than web browsers, because web browser is not support cordova plugins that depend on native platforms.

Upvotes: 1

Related Questions