【问题标题】:Where does my image been stored in Ionic application?我的图像存储在 Ionic 应用程序的什么位置?
【发布时间】:2018-04-27 02:58:10
【问题描述】:

我对 Ionic 和 Cordova 非常陌生,在过去的几天里,我正在尝试下载我上传到 Firebase 存储中的图像。我想通过我的移动应用程序传输图像并将其存储在我的移动设备中。我已经安装了执行此操作所需的所有插件。我创建了两个按钮。第一个按钮是在我的应用程序中显示图像,第二个按钮是在我的设备中下载图像。源代码在我的 storage.html 中

<ion-header>

  <ion-navbar>
    <ion-title>storage</ion-title>
  </ion-navbar>

</ion-header>


<ion-content padding>
 <button ion-button (click)="display()">Display</button>
 <button ion-button (click)="download()">Download</button>
 <img src="{{imgsource}}">
</ion-content>

功能在我的 storage.ts 中

import { Component, NgZone } from '@angular/core';

import { NavController, Platform, AlertController } from 'ionic-angular';
//import {File,Transfer} from 'ionic-native';
import {FileTransferObject } from '@ionic-native/file-transfer';
import {TransferObject} from '@ionic-native/transfer';
import {Transfer} from '@ionic-native/transfer';
import {File} from '@ionic-native/file';


import firebase from 'firebase';



declare var cordova: any;

@Component({
  selector: 'storage-home',
  templateUrl: 'storage.html',
  providers: [Transfer, TransferObject, File]
})



export class StoragePage {

  storageDirectory: string = '';
  fileTransfer: FileTransferObject;
  nativepath: any;
  firestore = firebase.storage();
  imgsource: any;
  constructor(public navCtrl: NavController, public platform: Platform, public alertCtrl: AlertController, public zone: NgZone) {
    this.platform.ready().then(() => {
      // make sure this is on a device, not an emulation (e.g. chrome tools device mode)
      if(!this.platform.is('cordova')) {
        return false;
      }

      if (this.platform.is('ios')) {
        this.storageDirectory = cordova.file.documentsDirectory;
      }
      else if(this.platform.is('android')) {
        this.storageDirectory = cordova.file.dataDirectory;
      }
      else {
        // exit otherwise, but you could add further types here e.g. Windows
        return false;
      }
    });
  }





     display() {
        this.firestore.ref().child('image.jpg').getDownloadURL().then((url) => {
          this.zone.run(() => {
            this.imgsource = url;
            this.fileTransfer.download(url,'image.jpg').then((entry) => {
           console.log('download complete: ' + entry.toURL());


           }, (error) => {
          // handle error
           });
           })
        })
      }

     downlad() {
        this.firestore.ref().child('image.jpg').getDownloadURL().then((url) => {
          this.zone.run(() => {
            this.imgsource = url;
            this.fileTransfer.download(url,cordova.file.dataDirectory +'image.jpg').then((entry) => {
           console.log('download complete: ' + entry.toURL());


           }, (error) => {
          // handle error
           });
           })
        })
      } 

    }

当我在我的设备上安装应用程序时,我可以看到我的图像,显​​示按钮可以完美运行。但问题在于下载按钮,因为什么都没有发生,我不知道它是否正常工作,因为我无法在设备的任何地方找到我的图像。谁能指导一下?

感谢您的问候

【问题讨论】:

    标签: android cordova firebase ionic-framework file-transfer


    【解决方案1】:

    您的下载函数名称似乎有误。在 HTML 模块中,您指的是 download(),在您的代码中,您的函数被标记为 downlad。

    【讨论】:

      猜你喜欢
      • 2014-06-29
      • 2014-07-11
      • 2021-01-22
      • 2017-03-06
      • 2011-01-27
      • 1970-01-01
      • 1970-01-01
      • 2023-03-30
      • 1970-01-01
      相关资源
      最近更新 更多