我试图在aws s3上上传图片,因为我使用@ionic native/file transfer,但是当我试图添加fileuploadoptions时,我得到了错误。filetransfer和filetransferobject不会出现错误。对于AWS S3,我需要FileUploadOptions.params
。
注意:我已经调查了node_modules/@ionic native/file transfer一些fileuploadoptions代码有注释。这是个问题吗?有人知道其他稳定的文件传输版本吗?我现在疯了
我已经用这些命令安装了脚本
$ ionic cordova plugin add cordova-plugin-file-transfer
$ npm install --save @ionic-native/file-transfer
然后我更新了app.module.ts:
import { FileTransfer, FileUploadOptions, FileTransferObject } from '@ionic-native/file-transfer';
在app.module.ts的provider数组中:
providers: [
StatusBar,
FileUploadOptions,
FileTransfer,
FileTransferObject,
File,
Camera,
SplashScreen,
{
provide: ErrorHandler,
useClass: IonicErrorHandler
},
{
provide: AuthHttp,
useFactory: getAuthHttp,
deps: [Http]
},
DataServiceProvider,
LocationServiceProvider,
Geolocation,
JwtHelper,
AuthServiceProvider
]
当我在提供程序数组中添加fileuploadoptions时,会出现以下错误:
typescript错误'fileuploadoptions'只引用一个类型,但是
在这里被用作一个值。
C:/xampp/htdocs/ionic/tellworld mobile/src/app/app.module.ts
状态栏,文件上传选项,文件传输,
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"
},
最佳答案
您只需要在FileTransfer
数组中包含providers
:
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
和FileTransferObject
不是提供程序,而是与插件交互时使用的类/接口。