首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >离子5电容器FileTransfer

离子5电容器FileTransfer
EN

Stack Overflow用户
提问于 2020-07-31 00:57:31
回答 1查看 3.2K关注 0票数 1

我正在浏览器中运行一个使用capacitor的ionic 5应用程序,并且我正在尝试使用文件传输功能。我遵循文档https://ionicframework.com/docs/native/file-transfer并使用电容器配置我的应用程序。因此运行:

代码语言:javascript
复制
npm install cordova-plugin-file-transfer
npm install @ionic-native/file-transfer
ionic cap sync

在我的app.module中,我注册了提供者:

代码语言:javascript
复制
import { FileTransfer } from '@ionic-native/file-transfer/ngx';
import { File } from '@ionic-native/file/ngx';

...
providers: [
        StatusBar,
        SplashScreen,
        ...
        FileTransfer,
        File
    ],

请注意,我还安装了本机文件包,因此总共有以下4个新包:

代码语言:javascript
复制
"@ionic-native/file": "^5.27.0",
"@ionic-native/file-transfer": "^5.27.0",
"cordova-plugin-file": "^6.0.2",
"cordova-plugin-file-transfer": "^1.7.1",

我在组件中的代码是:

代码语言:javascript
复制
import { Input, Component } from '@angular/core';
import { FileTransfer, FileTransferObject } from '@ionic-native/file-transfer/ngx';
import { File } from '@ionic-native/file/ngx';

@Component({
    selector: 'app-order-detail-order-card',
    templateUrl: './order-detail-order-card.page.html'
})
export class OrderDetailOrderCardPage {
    @Input() pdfUrl: string;
    @Input() orderCardId: string;

    constructor(private transfer: FileTransfer, private file: File) { }

    public downloadFile(): void {
        const fileTransfer: FileTransferObject = this.transfer.create();
        fileTransfer.download(this.pdfUrl, this.file.applicationDirectory + `${orderCardId}.pdf`).then((entry) => {
          console.log('download complete: ' + entry.toURL());
        }, (error) => {
          // handle error
        });
    }
}

当我在浏览器中运行应用程序时,我收到以下警告,并且我不确定文件是否应该加载到某个地方?

代码语言:javascript
复制
common.js:284 Native: tried calling SplashScreen.hide, but Cordova is not available. Make sure to include cordova.js or run in a device/simulator

即使我没有得到文件,我也希望看到“下载完成”的消息。我不是很清楚,我是否必须在我的应用程序中配置其他东西才能在本地运行它,或者我必须仅在模拟器或设备本身中使用此功能。

还需要配置什么才能使其正常工作?

EN

回答 1

Stack Overflow用户

发布于 2021-05-26 21:20:40

代码语言:javascript
复制
common.js:284 Native: tried calling SplashScreen.hide, but Cordova is not available. Make sure to include cordova.js or run in a device/simulator

这意味着你使用的浏览器模拟器没有任何闪屏,你可以完全忽略这个警告(你不会得到它使用模拟器或真实的设备)。

您还应该粘贴该页面的html部分,因为下载可能因为url不完整而无法启动,并且它不会继续使用"then()“

也许我错了,但这是可能的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63177906

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档