Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ionic: FileUploadOptions throw error when add to app.module.ts

I am trying to upload image on AWS s3, for that i am using @ionic-native/file-transfer But when i try to add FileUploadOptions i get errors. The errors doesn't occur with FileTransfer and FileTransferObject. I need FileUploadOptions.params for AWS s3.

Note: i've looked into node_modules/@ionic-native/file-transfer some FileUploadOptions code is commented. Is this a problem? do anyone know any other stable file-transfer version. I am out of my mind right now

I've installed the scripts using these commands

$ ionic cordova plugin add cordova-plugin-file-transfer
$ npm install --save @ionic-native/file-transfer

Than i updated my app.module.ts:

import { FileTransfer, FileUploadOptions, FileTransferObject } from '@ionic-native/file-transfer';

and in provider array of app.module.ts:

providers: [
        StatusBar,
        FileUploadOptions,
        FileTransfer,
        FileTransferObject,
        File,
        Camera,
        SplashScreen,
        { 
            provide: ErrorHandler, 
            useClass: IonicErrorHandler 
        },
        {
            provide: AuthHttp,
            useFactory: getAuthHttp,
            deps: [Http]
        },        
        DataServiceProvider,
        LocationServiceProvider,
        Geolocation,
        JwtHelper,
        AuthServiceProvider 
    ]

When ever i add FileUploadOptions in my provider array i get this error:

Typescript Error 'FileUploadOptions' only refers to a type, but is being used as a value here. C:/xampp/htdocs/ionic/tellworld-mobile/src/app/app.module.ts StatusBar, FileUploadOptions, FileTransfer,

package.json:

"dependencies": {
        "@angular/common": "4.1.3",
        "@angular/compiler": "4.1.3",
        "@angular/compiler-cli": "4.1.3",
        "@angular/core": "4.1.3",
        "@angular/forms": "4.1.3",
        "@angular/http": "4.1.3",
        "@angular/platform-browser": "4.1.3",
        "@angular/platform-browser-dynamic": "4.1.3",
        "@ionic-native/camera": "^4.2.1",
        "@ionic-native/core": "3.12.1",
        "@ionic-native/file": "^4.2.1",
        "@ionic-native/file-transfer": "^4.2.1",
        "@ionic-native/geolocation": "^4.1.0",
        "@ionic-native/splash-screen": "3.12.1",
        "@ionic-native/status-bar": "3.12.1",
        "@ionic/storage": "^2.0.1",
        "@ngui/map": "^0.18.4",
        "@types/googlemaps": "^3.26.20",
        "angular2-jwt": "^0.2.3",
        "cordova-ios": "^4.4.0",
        "cordova-plugin-camera": "^2.4.1",
        "cordova-plugin-console": "^1.0.5",
        "cordova-plugin-device": "^1.1.4",
        "cordova-plugin-file": "^4.3.3",
        "cordova-plugin-file-transfer": "1.6.3",
        "cordova-plugin-geolocation": "^2.4.3",
        "cordova-plugin-splashscreen": "^4.0.3",
        "cordova-plugin-statusbar": "^2.2.2",
        "cordova-plugin-whitelist": "^1.3.1",
        "cordova-sqlite-storage": "^2.0.4",
        "ionic-angular": "3.6.0",
        "ionic-plugin-keyboard": "^2.2.1",
        "ionicons": "3.0.0",
        "moment": "^2.18.1",
        "ngmap": "^1.18.4",
        "rxjs": "5.4.0",
        "sw-toolbox": "3.6.0",
        "zone.js": "0.8.12"
    },
"devDependencies": {
        "@ionic/app-scripts": "2.1.3",
        "ionic": "3.9.2",
        "typescript": "2.3.4"
    },
like image 495
MTA Avatar asked Sep 06 '17 06:09

MTA


1 Answers

You only need to include FileTransfer in the providers array:

providers: [
    StatusBar,
    // FileUploadOptions,
    // FileTransferObject,
    FileTransfer, // <--- This one!        
    File,
    Camera,
    SplashScreen,
    { 
        provide: ErrorHandler, 
        useClass: IonicErrorHandler 
    },
    {
        provide: AuthHttp,
        useFactory: getAuthHttp,
        deps: [Http]
    },        
    DataServiceProvider,
    LocationServiceProvider,
    Geolocation,
    JwtHelper,
    AuthServiceProvider 
]

FileUploadOptions and FileTransferObject are not providers, but just classes/interfaces that are used when interacting with the plugin.

like image 146
sebaferreras Avatar answered Oct 15 '22 19:10

sebaferreras