Alternatives for cordova-plugin-file-transfer FileTransfer download error code 3 - handshake failed in ionic application only on some Android Phones

hey there,

in my ionic application I always get an error trying to download a pdf document from our server using the cordova file transfer plugin:

public getDocument(url: string, filePath: string, fileName: string): Promise<boolean> {

    const fileTransfer = new Transfer();
    let headers = this.createHeader();
    let requestOptions = new RequestOptions({headers: headers});

    return this.documentPromise = new Promise((resolve, reject) => {
      fileTransfer.download(url, filePath + fileName, true, requestOptions)
        .then((entry) => {
          resolve(entry.toURL());
        })
        .catch((error) => {
          reject(error);
        });

It jumps directly into the catch case and gives the following error:

JSON.stringify(error)
>> "code": 3, "source": "http://...", "target": file:///...", "http_status": null, "body": null, "exception": "Handshake failed"

the “source” path looks like “asd.mysite.de/proxy/bill/app/pdfdocument”; and the file is reachable and downloadable from other devices. The “target” path looks like “file:///storage/emulated/0/Android/data/subdomain.domainnam‌​e.toplevdomain/files‌​/document.pdf”. On my phone by now there exists the path “/storage/emulated” and the rest of the path is never created.

This only happens on my Samsung A3, but not on other android phones or ios.

Any ideas on why this error might occur?

This is my running system:

cli packages: (D:\Users\...)

    @ionic/cli-utils  : 1.9.2
    ionic (Ionic CLI) : 3.9.2

global packages:

    Cordova CLI : 7.0.1

local packages:

    @ionic/app-scripts : 2.1.3
    Cordova Platforms  : android 6.2.3 browser 4.1.0
    Ionic Framework    : ionic-angular 3.6.0

System:

    Android SDK Tools : 26.0.2
    Node              : v6.11.0
    npm               : 5.3.0
    OS                : Windows 7

The relevant plugins are set with this version:

        "cordova-plugin-file": "^4.3.3",
        "cordova-plugin-file-opener2": "^2.0.19",
        "cordova-plugin-file-transfer": "^1.6.3",
        "cordova-plugin-whitelist": "^1.3.1",

I suppose this is a bug in the cordova file transfer plugin. Does anybody have a solution of downloading a pdf file without the cordova-plugin-file-transfer?

I use this plugin too. it work fine.

import { FileTransfer, FileTransferObject } from '@ionic-native/file-transfer';
import { File } from '@ionic-native/file';
constructor( 
    public transfer: FileTransfer, 
    public file: File, 
    ) {}
downloadFile(fileUrl){ 
    let fileTransfer: FileTransferObject = this.transfer.create();
    fileTransfer.download(fileUrl, this.file.dataDirectory + '1.pdf').then((entry) => {
      console.log('download complete: ' + entry.toURL()); 
    }, (error) => {
      console.log(error)
    });
}

Thanks for your code, I am doing it this way as well now, as described in the ionic documentation. It still throws the same “handshake failed exception”.

that maybe your url problem, the function is fine

Hi…I used same File Transfer Plugin, but more times it show as Connection Error with code 3.But when i download that file in browser, it can be downloaded fast.

1 Like

Is it something to do with HTTP instead of using HTTPS???
Were you able to resolve the issue? If so how?

Use below plugin to install apk or just to download files.
Even you can the functionality as per your need
Plugin for capacitor