离子3:Filetransfer下载,文件不在目录中,但没有错误代码

时间:2018-09-20 13:07:02

标签: ionic3 cordova-plugins file-transfer

我正尝试通过cordova FileTransfer插件使用Ionic3-App下载图像,并将其存储在设备上的this.file.dataDirectory中,然后再在应用程序中显示。

我正在我的android设备上对其进行测试。

当我尝试下载它时,它似乎可以正常工作,我获得了目录的路径,并且会触发成功警报,但是当我在文件系统中查找该文件时,该文件不存在。 该应用程序未与livereload一起运行,并且我已经降级了Webview!

如果有人可以找到解决方案,那将很酷。

这是我的代码:

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    // Insert code here to initialize your application


    NSRect windowFrame = self.window.frame;
    NSRect childWindowFrame = {
        .origin.x = CGRectGetMidX(windowFrame) - 25,
        .origin.y = CGRectGetMinY(windowFrame) - 25,
        .size.width = 50,
        .size.height = 50,
    };

    NSWindow *childWindow = [[NSWindow alloc] initWithContentRect:childWindowFrame
                                                        styleMask:NSWindowStyleMaskBorderless
                                                          backing:NSBackingStoreBuffered
                                                            defer:YES];
    childWindow.backgroundColor = [NSColor clearColor];
    childWindow.contentView.wantsLayer = YES;
    childWindow.contentView.layer.backgroundColor = [NSColor redColor].CGColor;
    childWindow.contentView.layer.cornerRadius = 25.0;



    [self.window addChildWindow:childWindow ordered:NSWindowAbove];
}

离子信息:

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { AlertController } from 'ionic-angular';
import { File } from '@ionic-native/file';
import { FileTransfer, FileTransferObject } from '@ionic-native/file-transfer';
import { normalizeURL } from 'ionic-angular';

@Component({
  selector: 'page-online',
  templateUrl: 'online.html'
})

export class OnlinePage {

  private alert:any;
  public fileUrl:any = '';


  constructor(
    public navCtrl: NavController, 
    public alertCtrl: AlertController, 
    private file: File, 
    private transfer: FileTransfer) {
  }

    download(){
        this.downloadFile();
    }

    downloadFile(){
      let fileTransfer: FileTransferObject = this.transfer.create();
      let url = 'http://example.com/png/example.png';

      fileTransfer.download(url, this.file.dataDirectory + 'Textmaterial_Homepage.pdf', true).then((entry) => {
        var imagePath = entry.toURL();
        this.fileUrl = normalizeURL(imagePath);
        this.showAlert("File was downloaded","Path: " + this.fileUrl);
      })
      .catch(() => {
        this.showAlert("File was not downloaded","Try again!");
      }
     );
    }

  } 

0 个答案:

没有答案