Git Product home page Git Product logo

cordova-plugin-file-transfer's Introduction

title description
File Transfer
Upload and download files.

cordova-plugin-file-transfer

Android Testsuite Chrome Testsuite iOS Testsuite Lint Test

Usage notice

With the new features introduced in the Fetch API and the XMLHttpRequest, this plugin may not be needed any more for your use case. For small file transfers, you probably won't require this plugin. But, if you plan to handle large downloads, suffering from slow saving, timeouts, or crashes, this plugin is better suited for your use case over the Fetch API or the XMLHttpRequest.

Migrating from this plugin to using the new features of XMLHttpRequest, is explained in this Cordova blog post.

Description

This plugin allows you to upload and download files.

This plugin defines global FileTransfer, FileUploadOptions constructors. Although in the global scope, they are not available until after the deviceready event.

document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
    console.log(FileTransfer);
}

To get a few ideas, check out the sample at the bottom of this page.

Report issues with this plugin on the Apache Cordova issue tracker

Installation

cordova plugin add cordova-plugin-file-transfer

Supported Platforms

  • Android
  • Browser
  • iOS

FileTransfer

The FileTransfer object provides a way to upload files using an HTTP multi-part POST or PUT request, and to download files.

Properties

  • onprogress: Called with a ProgressEvent whenever a new chunk of data is transferred. (Function)

Methods

  • upload: Sends a file to a server.

  • download: Downloads a file from server.

  • abort: Aborts an in-progress transfer.

upload

Parameters:

  • fileURL: Filesystem URL representing the file on the device or a data URI. For backwards compatibility, this can also be the full path of the file on the device. (See Backwards Compatibility Notes below)

  • server: URL of the server to receive the file, as encoded by encodeURI().

  • successCallback: A callback that is passed a FileUploadResult object. (Function)

  • errorCallback: A callback that executes if an error occurs retrieving the FileUploadResult. Invoked with a FileTransferError object. (Function)

  • options: Optional parameters (Object). Valid keys:

    • fileKey: The name of the form element. Defaults to file. (DOMString)
    • fileName: The file name to use when saving the file on the server. Defaults to image.jpg. (DOMString)
    • httpMethod: The HTTP method to use - either PUT or POST. Defaults to POST. (DOMString)
    • mimeType: The mime type of the data to upload. Defaults to image/jpeg. (DOMString)
    • params: A set of optional key/value pairs to pass in the HTTP request. (Object, key/value - DOMString)
    • chunkedMode: Whether to upload the data in chunked streaming mode. Defaults to true. (Boolean)
    • headers: A map of header name/header values. Use a hash to specify one or more than one value. On iOS, FireOS, and Android, if a header named Content-Type is present, multipart form data will NOT be used. (Object)
  • trustAllHosts: Optional parameter, defaults to false. If set to true, it accepts all security certificates. Not recommended for production use. Supported on iOS. (boolean)

Example

// !! Assumes variable fileURL contains a valid URL to a text file on the device,
//    for example, cdvfile://localhost/persistent/path/to/file.txt

var win = function (r) {
    console.log("Code = " + r.responseCode);
    console.log("Response = " + r.response);
    console.log("Sent = " + r.bytesSent);
}

var fail = function (error) {
    alert("An error has occurred: Code = " + error.code);
    console.log("upload error source " + error.source);
    console.log("upload error target " + error.target);
}

var options = new FileUploadOptions();
options.fileKey = "file";
options.fileName = fileURL.substr(fileURL.lastIndexOf('/') + 1);
options.mimeType = "text/plain";

var params = {};
params.value1 = "test";
params.value2 = "param";

options.params = params;

var ft = new FileTransfer();
ft.upload(fileURL, encodeURI("http://some.server.com/upload.php"), win, fail, options);

Example with Upload Headers and Progress Events (Android and iOS only)

function win(r) {
    console.log("Code = " + r.responseCode);
    console.log("Response = " + r.response);
    console.log("Sent = " + r.bytesSent);
}

function fail(error) {
    alert("An error has occurred: Code = " + error.code);
    console.log("upload error source " + error.source);
    console.log("upload error target " + error.target);
}

var uri = encodeURI("http://some.server.com/upload.php");

var options = new FileUploadOptions();
options.fileKey="file";
options.fileName=fileURL.substr(fileURL.lastIndexOf('/')+1);
options.mimeType="text/plain";

var headers={'headerParam':'headerValue', 'headerParam2':'headerValue2'};

options.headers = headers;

var ft = new FileTransfer();
var progressValue = 0;
ft.onprogress = function(progressEvent) {
    if (progressEvent.lengthComputable) {
        // Calculate the percentage
        progressValue = progressEvent.loaded / progressEvent.total;
    } else {
        progressValue++;
    }

    // Display percentage in the UI
    document.getElementByID('progress-value').innerHTML = progressValue;
};
ft.upload(fileURL, uri, win, fail, options);

FileUploadResult

A FileUploadResult object is passed to the success callback of the FileTransfer object's upload() method.

Properties

  • bytesSent: The number of bytes sent to the server as part of the upload. (long)

  • responseCode: The HTTP response code returned by the server. (long)

  • response: The HTTP response returned by the server. (DOMString)

  • headers: The HTTP response headers by the server. (Object)

    • Currently supported on iOS only.

iOS Quirks

  • Does not support responseCode or bytesSent.

  • Does not support uploads of an empty file with chunkedMode=true and multipartMode=false.

Browser Quirks

  • withCredentials: boolean that tells the browser to set the withCredentials flag on the XMLHttpRequest

download

Parameters:

  • source: URL of the server to download the file, as encoded by encodeURI().

  • target: Filesystem url representing the file on the device. For backwards compatibility, this can also be the full path of the file on the device. (See Backwards Compatibility Notes below)

  • successCallback: A callback that is passed a FileEntry object. (Function)

  • errorCallback: A callback that executes if an error occurs when retrieving the FileEntry. Invoked with a FileTransferError object. (Function)

  • trustAllHosts: Optional parameter, defaults to false. If set to true, it accepts all security certificates. Not recommended for production use. Supported on iOS. (boolean)

  • options: Optional parameters, currently only supports headers (such as Authorization (Basic Authentication), etc).

Example

// !! Assumes variable fileURL contains a valid URL to a path on the device,
//    for example, cdvfile://localhost/persistent/path/to/downloads/

var fileTransfer = new FileTransfer();
var uri = encodeURI("http://some.server.com/download.php");

fileTransfer.download(
    uri,
    fileURL,
    function(entry) {
        console.log("download complete: " + entry.toURL());
    },
    function(error) {
        console.log("download error source " + error.source);
        console.log("download error target " + error.target);
        console.log("download error code" + error.code);
    },
    false,
    {
        headers: {
            "Authorization": "Basic dGVzdHVzZXJuYW1lOnRlc3RwYXNzd29yZA=="
        }
    }
);

Browser Quirks

  • withCredentials: boolean that tells the browser to set the withCredentials flag on the XMLHttpRequest

abort

Aborts an in-progress transfer. The onerror callback is passed a FileTransferError object which has an error code of FileTransferError.ABORT_ERR.

Example

// !! Assumes variable fileURL contains a valid URL to a text file on the device,
//    for example, cdvfile://localhost/persistent/path/to/file.txt

var win = function(r) {
    console.log("Should not be called.");
}

var fail = function(error) {
    // error.code == FileTransferError.ABORT_ERR
    alert("An error has occurred: Code = " + error.code);
    console.log("upload error source " + error.source);
    console.log("upload error target " + error.target);
}

var options = new FileUploadOptions();
options.fileKey="file";
options.fileName="myphoto.jpg";
options.mimeType="image/jpeg";

var ft = new FileTransfer();
ft.upload(fileURL, encodeURI("http://some.server.com/upload.php"), win, fail, options);
ft.abort();

FileTransferError

A FileTransferError object is passed to an error callback when an error occurs.

Properties

  • code: One of the predefined error codes listed below. (Number)

  • source: URL to the source. (String)

  • target: URL to the target. (String)

  • http_status: HTTP status code. This attribute is only available when a response code is received from the HTTP connection. (Number)

  • body Response body. This attribute is only available when a response is received from the HTTP connection. (String)

  • exception: Either e.getMessage or e.toString (String)

iOS Quirks

exception is never defined.

Constants

  • 1 = FileTransferError.FILE_NOT_FOUND_ERR
  • 2 = FileTransferError.INVALID_URL_ERR
  • 3 = FileTransferError.CONNECTION_ERR
  • 4 = FileTransferError.ABORT_ERR
  • 5 = FileTransferError.NOT_MODIFIED_ERR

Backwards Compatibility Notes

Previous versions of this plugin would only accept device-absolute-file-paths as the source for uploads, or as the target for downloads. These paths would typically be of the form:

/var/mobile/Applications/<application UUID>/Documents/path/to/file  (iOS)
/storage/emulated/0/path/to/file                                    (Android)

For backwards compatibility, these paths are still accepted, and if your application has recorded paths like these in persistent storage, then they can continue to be used.

These paths were previously exposed in the fullPath property of FileEntry and DirectoryEntry objects returned by the File plugin. New versions of the File plugin however, no longer expose these paths to JavaScript.

If you are upgrading to a new (1.0.0 or newer) version of File, and you have previously been using entry.fullPath as arguments to download() or upload(), then you will need to change your code to use filesystem URLs instead.

FileEntry.toURL() and DirectoryEntry.toURL() return a filesystem URL of the form:

cdvfile://localhost/persistent/path/to/file

which can be used in place of the absolute file path in both download() and upload() methods.

Sample: Download and Upload Files

Use the File-Transfer plugin to upload and download files. In these examples, we demonstrate several tasks like:

Download a Binary File to the application cache

Use the File plugin with the File-Transfer plugin to provide a target for the files that you download (the target must be a FileEntry object). Before you download the file, create a DirectoryEntry object by using resolveLocalFileSystemURL and calling fs.root in the success callback. Use the getFile method of DirectoryEntry to create the target file.

window.requestFileSystem(window.TEMPORARY, 5 * 1024 * 1024, function (fs) {

    console.log('file system open: ' + fs.name);

    // Make sure you add the domain name to the Content-Security-Policy <meta> element.
    var url = 'http://cordova.apache.org/static/img/cordova_bot.png';
    // Parameters passed to getFile create a new file or return the file if it already exists.
    fs.root.getFile('downloaded-image.png', { create: true, exclusive: false }, function (fileEntry) {
        download(fileEntry, url, true);

    }, onErrorCreateFile);

}, onErrorLoadFs);

Note For persistent storage, pass LocalFileSystem.PERSISTENT to requestFileSystem.

When you have the FileEntry object, download the file using the download method of the FileTransfer object. The 3rd argument to the download function of FileTransfer is the success callback, which you can use to call the app's readBinaryFile function. In this code example, the entry variable is a new FileEntry object that receives the result of the download operation.

function download(fileEntry, uri, readBinaryData) {

    var fileTransfer = new FileTransfer();
    var fileURL = fileEntry.toURL();

    fileTransfer.download(
        uri,
        fileURL,
        function (entry) {
            console.log("Successful download...");
            console.log("download complete: " + entry.toURL());
            if (readBinaryData) {
              // Read the file...
              readBinaryFile(entry);
            }
            else {
              // Or just display it.
              displayImageByFileURL(entry);
            }
        },
        function (error) {
            console.log("download error source " + error.source);
            console.log("download error target " + error.target);
            console.log("upload error code" + error.code);
        },
        null, // or, pass false
        {
            //headers: {
            //    "Authorization": "Basic dGVzdHVzZXJuYW1lOnRlc3RwYXNzd29yZA=="
            //}
        }
    );
}

If you just need to display the image, take the FileEntry to call its toURL() function.

function displayImageByFileURL(fileEntry) {
    var elem = document.getElementById('imageElement');
    elem.src = fileEntry.toURL();
}

Depending on your app requirements, you may want to read the file. To support operations with binary files, FileReader supports two methods, readAsBinaryString and readAsArrayBuffer. In this example, use readAsArrayBuffer and pass the FileEntry object to the method. Once you read the file successfully, construct a Blob object using the result of the read.

function readBinaryFile(fileEntry) {
    fileEntry.file(function (file) {
        var reader = new FileReader();

        reader.onloadend = function() {

            console.log("Successful file read: " + this.result);
            // displayFileData(fileEntry.fullPath + ": " + this.result);

            var blob = new Blob([new Uint8Array(this.result)], { type: "image/png" });
            displayImage(blob);
        };

        reader.readAsArrayBuffer(file);

    }, onErrorReadFile);
}

Once you read the file successfully, you can create a DOM URL string using createObjectURL, and then display the image.

function displayImage(blob) {

    // Note: Use window.URL.revokeObjectURL when finished with image.
    var objURL = window.URL.createObjectURL(blob);

    // Displays image if result is a valid DOM string for an image.
    var elem = document.getElementById('imageElement');
    elem.src = objURL;
}

As you saw previously, you can call FileEntry.toURL() instead to just display the downloaded image (skip the file read).

Upload a File

When you upload a File using the File-Transfer plugin, use the File plugin to provide files for upload (again, they must be FileEntry objects). Before you can upload anything, create a file for upload using the getFile method of DirectoryEntry. In this example, create the file in the application's cache (fs.root). Then call the app's writeFile function so you have some content to upload.

function onUploadFile() {
    window.requestFileSystem(window.TEMPORARY, 5 * 1024 * 1024, function (fs) {

        console.log('file system open: ' + fs.name);
        var fileName = "uploadSource.txt";
        var dirEntry = fs.root;
        dirEntry.getFile(fileName, { create: true, exclusive: false }, function (fileEntry) {

            // Write something to the file before uploading it.
            writeFile(fileEntry);

        }, onErrorCreateFile);

    }, onErrorLoadFs);
}

In this example, create some simple content, and then call the app's upload function.

function writeFile(fileEntry, dataObj) {
    // Create a FileWriter object for our FileEntry (log.txt).
    fileEntry.createWriter(function (fileWriter) {

        fileWriter.onwriteend = function () {
            console.log("Successful file write...");
            upload(fileEntry);
        };

        fileWriter.onerror = function (e) {
            console.log("Failed file write: " + e.toString());
        };

        if (!dataObj) {
          dataObj = new Blob(['file data to upload'], { type: 'text/plain' });
        }

        fileWriter.write(dataObj);
    });
}

Forward the FileEntry object to the upload function. To perform the actual upload, use the upload function of the FileTransfer object.

function upload(fileEntry) {
    // !! Assumes variable fileURL contains a valid URL to a text file on the device,
    var fileURL = fileEntry.toURL();

    var success = function (r) {
        console.log("Successful upload...");
        console.log("Code = " + r.responseCode);
        // displayFileData(fileEntry.fullPath + " (content uploaded to server)");
    }

    var fail = function (error) {
        alert("An error has occurred: Code = " + error.code);
    }

    var options = new FileUploadOptions();
    options.fileKey = "file";
    options.fileName = fileURL.substr(fileURL.lastIndexOf('/') + 1);
    options.mimeType = "text/plain";

    var params = {};
    params.value1 = "test";
    params.value2 = "param";

    options.params = params;

    var ft = new FileTransfer();
    // SERVER must be a URL that can handle the request, like
    // http://some.server.com/upload.php
    ft.upload(fileURL, encodeURI(SERVER), success, fail, options);
};

Download the uploaded file

To download the image you just uploaded, you will need a valid URL that can handle the request, for example, http://some.server.com/download.php. Again, the success handler for the FileTransfer.download method receives a FileEntry object. The main difference here from previous examples is that we call FileReader.readAsText to read the result of the download operation, because we uploaded a file with text content.

function download(fileEntry, uri) {

    var fileTransfer = new FileTransfer();
    var fileURL = fileEntry.toURL();

    fileTransfer.download(
        uri,
        fileURL,
        function (entry) {
            console.log("Successful download...");
            console.log("download complete: " + entry.toURL());
            readFile(entry);
        },
        function (error) {
            console.log("download error source " + error.source);
            console.log("download error target " + error.target);
            console.log("upload error code" + error.code);
        },
        null, // or, pass false
        {
            //headers: {
            //    "Authorization": "Basic dGVzdHVzZXJuYW1lOnRlc3RwYXNzd29yZA=="
            //}
        }
    );
}

In the readFile function, call the readAsText method of the FileReader object.

function readFile(fileEntry) {
    fileEntry.file(function (file) {
        var reader = new FileReader();

        reader.onloadend = function () {

            console.log("Successful file read: " + this.result);
            // displayFileData(fileEntry.fullPath + ": " + this.result);

        };

        reader.readAsText(file);

    }, onErrorReadFile);
}

cordova-plugin-file-transfer's People

Contributors

agrieve avatar alsorokin avatar breautek avatar clelland avatar cmarcelk avatar dblotsky avatar dependabot[bot] avatar dpogue avatar erisu avatar filmaj avatar hardeep avatar hermwong avatar infil00p avatar janpio avatar jcesarmobile avatar jpuerto avatar kaynz avatar ldeluca avatar lmnbeyond avatar macdonst avatar maverickmishra avatar nikhilkh avatar purplecabbage avatar shazron avatar stacic avatar stevengill avatar surajpindoria avatar timbru31 avatar timkim avatar vladimir-kotikov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cordova-plugin-file-transfer's Issues

how to update file name dynametically when upload in ionic 4

hi, i am using Ionic 4 with angilar 7 in my project. currently i am facing difficulties on upload image. it works fine with static name like

let options: FileUploadOptions = {
         fileKey: 'file',
         fileName: 'name.jpg',
         headers: {}
         .....
      }

it working fine. but i need dynamic name. so i updated accordingly

    this.temp_image_name = new Date().getTime()+'.jpg';
    this.temp_image_name =  new Date().getTime()+'.jpg';
    let options: FileUploadOptions = {
         fileKey: 'file',
         fileName: this.temp_image_name,
         headers: {}
         .....
      }

but it not working and file name return empty. have any idea on this issue. Thanks

iOS: Download encounters "Invalid Server URL" if source file path contains non-English characters

Bug Report

Problem

File Transfer reports error when attempting to download a remote file with non-EN characters in the path/name. The file can be opened in browser with no issue.

What is expected to happen?

Should download correctly regardless of the name.

What does actually happen?

File Transfer Error: Invalid server URL https://xxxxxxxxx/SOME CHINESE CHARACTERS.pdf

Information

I am using this in combination with Ionic 3.

Command or Code

downloadRemoteFile(downloadUrl, path, fileName){ const transfer = this.ft.create(); transfer.download(downloadUrl, path + fileName, true).then(entry => { let url = entry.toURL(); this.openFileByPlatform(url); },(err) => { alert('download error'); }); }

Environment, Platform, Device

Only happens on iOS devices (tested on iOS 12+). Android is fine.

Version information

"ionic-angular": "3.9.2",
"cordova-ios": "4.5.5",
"cordova-plugin-file-transfer": "1.7.1",
"@ionic-native/file-transfer": "^5.0.0",

Workaround

Currently I need to modify the following line in CDVFileTransfer.m to fix the issue.
LINE 452:
Original:
NSURL* sourceURL = [NSURL URLWithString:source];
Modified:
NSURL* sourceURL = [NSURL URLWithString:[source stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]];

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above

Upload with method PUT not send parameters

I have a problem with sending image using method put. The parameters not sending.

var options = {
fileKey: "foto",
fileName: 'foto.jpg',
chunkedMode: false,
params: {'ok': 'teste'},
httpMethod: 'PUT'
};

iOS: Upload encounters "Invalid URL server" with DATA_URL destinationType

Bug Report

fileTransfer.upload(...) returns an error with a DATA_URL destinationType. Works well with Android.

Problem

I've been working on an upload function but fileTransfer.upload(...) returns an error when attempting to upload an image using an API.

Screen Shot 2019-10-03 at 5 19 37 PM

What is expected to happen?

Upload data with image successfully to a remote server.

What does actually happen?

File Transfer Error: Invalid server URL ENDPOINT [696:88559] FileTransferError { code = 2; source = "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAASABIAAD/4QBYRXhpZgAATU0AKgAAAAgAAgESAAMAAAABAAYAAIdpAAQAAAABAAAAJgAAAAAAA6ABAAMAAAABAAEAAKACAAQAAAABAAAFAKADAAQAAAABAAADwAAAAAD/7QA4UGhvdG9zaG9wIDMuMAA4QklNBAQA...

Information

I'm using this with Ionic 5.

Command or Code

`
.this.camera.getPicture(cameraOptions).then((imageData) => {

                  this.yourImage = 'data:image/jpeg;base64,' + imageData;

                  const endPoint = API_ENDPOINT;

                  fileTransfer.upload(this.yourImage, endPoint, options)
                    .then(
                      (data) => {
                        this.dismiss();
                       
                        $('.on-success').show();
                            ...
                      },
                      (err) => {
                        this.dismiss();
                        this.presentAlertConfirm(JSON.stringify(err));
                  });
                  this.dismiss();
                }, (err) => {
                    this.dismiss();
                    this.presentAlertConfirm(JSON.stringify(err));
                });`

Environment, Platform, Device

Testing on iPad mini 2 with iOS version 12.3.1.

Version information

  • MacOS Mojave 10.14.6
  • XCode 11
  • Ionic 5.4.2
  • Cordova 9.0.0
  • Node 6.9.0

Checklist

  • I updated all Cordova tooling to most recent version
  • I searched for existing GitHub issues
  • I included all the necessary information above

MacOS Support?

Hello everybody,
Any macOS support?
Is there any alternative for this plugin that's work on MacOS?

Thanks!

File download doesn't ask for permission

Bug Report

File download on android doesn't ask for the permission for storage permission. So when I call the download it gets rejected because of permission denied

Problem

What is expected to happen?

Ask for permission before download if it doesn't have storage permission

What does actually happen?

The download fails with permission denied.

Information

In the docs it is mentioned how to ask for permission https://ionicframework.com/docs/native/android-permissions
have to ask for https://developer.android.com/reference/android/Manifest.permission.html#WRITE_EXTERNAL_STORAGE permission before.

Command or Code

Environment, Platform, Device

Version information

Checklist

  • I searched for existing GitHub issues
  • [X ] I updated all Cordova tooling to most recent version
  • [X ] I included all the necessary information above

upload error code 3 "Software caused connection abort"

I did a circular upload of photos to request the server, but in the middle of the circle there were the following mistakes "Software caused connection abort", which left me at a loss.
Here is a code I uploaded.
let tempOptions: FileUploadOptions = { fileKey: 'file', fileName: photoDto.PhotoName, params: { type: photoType.ThumbPhoto, paramInfo: JSON.stringify(uploadPhotoDto) }, chunkedMode: false } tempOptions.headers = { Connection: "close" } this.fileTransfer.upload(this.file.externalDataDirectory + photoDto.PhotoTempPath + photoDto.PhotoName, url, tempOptions, true).then(res => { })

IOS 13 Video files are not uploading

Bug Report

IOS 13 Big video files are not uploading.

Problem

We have an app which uploads video,audio,images and docs to the server. Prior ios 13 that is ios 12 the video files used to upload whether large or small. But now large file size with above 50MB size are failing to upload to the server.

What is expected to happen?

Large video files with the size more than 50MB should upload, which used to happen and is happening in the lower versions of ios but having an issue in IOS 13.

What does actually happen?

When we try to upload a large file with a size of 52MB it just throws error to the cordova side.

Information

Have also checked in the Objective c code (CDVfiletranfer.m) of the file transfer plugin. this is the error which i was getting in the xcode.

2019-11-11 17:35:18.322215+0530 OfficerReports[2975:1293164] -[CDVFileTransfer requestForUploadCommand:fileData:]
[Line 224] fileData length: 52041341

2019-11-11 17:35:18.393344+0530 OfficerReports[2975:1293164] THREAD WARNING: ['FileTransfer'] took '71.375977' ms. Plugin should use a background thread.

2019-11-11 17:35:19.946234+0530 OfficerReports[2975:1294084] File Transfer Finished with response code 413

2019-11-11 17:35:19.947255+0530 OfficerReports[2975:1294084] FileTransferError {
body = "The page was not displayed because the request entity is too large.";
code = 3;
"http_status" = 413;
source = "file:///var/mobile/Containers/Data/Application/0D7E7F52-76FE-4541-992C-87FFA4484FD3/tmp/trim.BC29DB30-721B-4698-AC7F-5499B7BB24E3.MOV";
target = "https://officerreports.net/api/FileUpload/Upload";
}

Command or Code

Environment, Platform, Device

Platform : IOS
Device: IOS 13 devices

Version information

latest cordova file transfer plugin,
xcode version 11.2.1

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above

Will there be any more releases after 1.7.1?

1.7.1 was released Jan 2018 and there's been new code merged to master since then. I know the plugin is deprecated, but I wasn't sure if that meant there would no longer be releases.

I'd like to get the new changes from master using the standard installation method. I'm aware that I can manually pull master.

Will there be any more releases after 1.7.1?

Camera Images fail to upload on iPhone

Bug Report

Problem

What is expected to happen?

I'm able to successfully upload an image selected from library. I expect to capture an image and successfully upload an image from the camera in the same way as the library selection.

What does actually happen?

When I select camera and upload image from the camera I always get a 500 error. However, the image never makes it to my server so there isn't an error on the server side.

Information

Command or Code

else if (this.platform.is('ios') && sourceType === this.camera.PictureSourceType.CAMERA) {
                console.log('iPhone camera!');

                var currentName = imagePath.substr(imagePath.lastIndexOf('/') + 1);
                var correctPath = imagePath.substr(0, imagePath.lastIndexOf('/') + 1);
                let fileTransfer: FileTransfer = new FileTransfer()
                let options: FileUploadOptions = {
                    fileKey: 'image',
                    fileName: currentName,
                    chunkedMode: false,
                    headers: {
                        "Application": "MyApp",
                        "Authorization": "Bearer " + localStorage.getItem(StorageKey.AccessToken)
                    }
                }
                fileTransfer.create().upload(normalizeURL(imagePath), encodeURI(this.uploadLink), options, true).then(result => {
                    console.log('File transfer result: ', result);
                }).catch(err => {
                    console.log('Error with file transfer: ', err);
                });
            }

Environment, Platform, Device

iPhone XR
iOS: 12.3.1

Version information

Ionic:

Ionic CLI : 5.2.1 (/usr/local/lib/node_modules/ionic)
Ionic Framework : ionic-angular 3.9.5
@ionic/app-scripts : 3.2.2

Cordova:

Cordova CLI : 9.0.0 ([email protected])
Cordova Platforms : ios 5.0.1
Cordova Plugins : cordova-plugin-ionic-keyboard 2.1.3, (and 27 other plugins)

Utility:

cordova-res : not installed
native-run : 0.2.7

System:

Android SDK Tools : 26.1.1 (/Users/travis.bradfield/Library/Android/sdk)
ios-deploy : 1.9.4
ios-sim : 8.0.1
NodeJS : v10.15.0 (/usr/local/bin/node)
npm : 6.9.2
OS : macOS Mojave
Xcode : Xcode 10.2.1 Build version 10E1001

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above

Authentication using cookies

If I'm connecting to my server using AJAX calls with the option

xhrFields: { withCredentials: true },

how can I do this in calls to FileTransfer? It appears that FileTransfer only supports basic authentication.

Missing any permission information within this plugin's documentation?

Bug Report

I created an app that works like a charm on two of my phones and one tablet.
The app downloads a ZIP file from my server to cordova.file.externalDataDirectory.
One some users though, the download does not even start.

Problem

On some user's phone, the download does not even start

What is expected to happen?

Download a ZIP from http://www.myserver.com/thezip.zip to the external app's data folder.

What does actually happen?

On my devices everything is fine.
On a friend's Huawei phone, the download does not even start and i get no error info.
I thought that this is due to any needed app permissions, but he checked that the app has
a storage permission.
It would be awesome if there could be any information or an example within the documentation about the necessary lines of permissions needed in config.xml

Information

Made with latest Phonegap.
App is available in Play store (Remember the .GIF)

Command or Code

Via Cordova Run Android.

Environment, Platform, Device

Works under a Samsung, BQ and Lenovo device.
Does NOT work with a Huawei device (and so, probably others too)

Version information

cordova-plugin-android-permission 1.0.0
cordova-plugin-file 6.0.2
cordova-plugin-file-transfer 1.7.1
cordova-plugin-whitelist 1.3.4.
cordova-plugin-zip 3.1.0
cordova-plugin-contentsync 1.4.2

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above

SSLHandshakeException: Chain validation failed

Problem

SSL Handshake is failing. When a file is uploaded to the server, I am getting the error: W/FileTransfer: Error getting HTTP status code from connection. javax.net.ssl.SSLHandshakeException: Chain validation failed

What is expected to happen?

The SSL is valid until April 2019. The SSL is generated by Let's Encrypt Authority X3. Chrome or other browsers does not have this error. So the upload should work since the SSL is valid and TLS v1.2 is enabled.

What does actually happen?

If I upload from ionic mobile app using the native XHR method, it works. If I upload using the File Transfer plugin, the SSL Handshake fails. Particularly, it appears users with Android phones are having this issue.

Information

I did a scan using ssllabs.com and the only 2 things I found in that are:

  1. OCSP STAPLING ERROR: OCSP response expired on Mon Mar 04 16:00:00 UTC 2019

  2. TLS 1.1 and TLS 1.0 is not enabled. I am not sure if we need that since most of the users who have reported this uses Android 8+.

Can any of the above cause this SSL Handshake issue? Can an expired OCSP stapling cause this handshake error on uploads in File Transfer plugin?

Environment, Platform, Device

User 1:
OS: android 9 
Browser: chrome 72.0.3626.105 

User 2: 
OS: android 8.0.0 
Browser: chrome 72.0.3626.105 

User 3: 
OS: android 8.1.0 
Browser: chrome 72.0.3626.105 

Version information

code-push 2.0.4 "CodePushAcquisition"
cordova-android-support-gradle-release 1.4.2 "cordova-android-support-gradle-release"
cordova-plugin-appcenter-analytics 0.1.4 "App Center Analytics for Cordova"
cordova-plugin-appcenter-crashes 0.1.4 "App Center Crashes for Cordova"
cordova-plugin-appcenter-shared 0.1.3 "App Center shared code for Cordova"
cordova-plugin-camera 4.0.3 "Camera"
cordova-plugin-code-push 1.11.10 "CodePush"
cordova-plugin-device 2.0.2 "Device"
cordova-plugin-dialogs 2.0.1 "Notification"
cordova-plugin-file 6.0.1 "File"
cordova-plugin-file-opener2 2.0.19 "File Opener2"
cordova-plugin-file-transfer 1.7.1 "File Transfer"
cordova-plugin-headercolor 1.0 "HeaderColor"
cordova-plugin-ignore-lint-translation 0.0.1 "cordova-plugin-ignore-lint-translation"
cordova-plugin-ionic-webview 2.3.1 "cordova-plugin-ionic-webview"
cordova-plugin-ios-camera-permissions 1.2.0 "iOS Permissions"
cordova-plugin-mediapicker-dmcbig 2.3.8 "MediaPicker"
cordova-plugin-network-information 2.0.1 "Network Information"
cordova-plugin-splashscreen 5.0.2 "Splashscreen"
cordova-plugin-statusbar 2.4.2 "StatusBar"
cordova-plugin-whitelist 1.3.3 "Whitelist"
cordova-plugin-zip 3.1.0 "cordova-plugin-zip"
ionic-plugin-deeplinks 1.0.15 "Ionic Deeplink Plugin"
ionic-plugin-keyboard 2.2.1 "Keyboard"
cli packages: (/usr/local/lib/node_modules)

    @ionic/cli-utils  : 1.19.2
    ionic (Ionic CLI) : 3.20.0

global packages:

    cordova (Cordova CLI) : 8.0.0 

local packages:

    Cordova Platforms : android 7.0.0 ios 4.5.5
    Ionic Framework   : ionic1 1.3.3

System:

    ios-deploy : 1.9.2 
    ios-sim    : 5.0.13 
    Node       : v9.3.0
    npm        : 5.7.1 
    OS         : macOS
    Xcode      : Xcode 10.1 Build version 10B61 

Environment Variables:

    ANDROID_HOME : not set

Misc:

    backend : pro

iOS Library/NoCloud not being restored

My app is using Library/NoCloud on iOS to store all its data. It builds up a directory structure. When doing a backup and restoring it to a new phone, alle the directories and files are gone. It doesn't matter if I do a "iCloud" backup or a "Backup to this computer" with iTunes.

Is Library/NoCloud not part of any backup? Apple's documentation says that the complete app data is part of the backup.

Ios13 downloads always fail

Bug Report

Problem

What is expected to happen?

What does actually happen?

Information

Command or Code

Environment, Platform, Device

Version information

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above

iOS location issue on uploading the apptore - ask for NSLocationAlwaysUsageDescription

Hi,
I got the following message from apple once I uploaded the app to the app store.

Missing Purpose String in Info.plist File - Your app's code references one or more APIs that access sensitive user data. The app's Info.plist file should contain a NSLocationAlwaysUsageDescription key with a user-facing purpose string explaining clearly and completely why your app needs the data. Starting Spring 2019, all apps submitted to the App Store that access user data will be required to include a purpose string. If you're using external libraries or SDKs, they may reference APIs that require a purpose string. While your app might not use these APIs, a purpose string is still required. You can contact the developer of the library or SDK and request they release a version of their code that doesn't contain the APIs. Learn more (https://developer.apple.com/documentation/uikit/core_app/protecting_the_user_s_privacy).Thanks so much for filing an issue or feature request! Please fill out the following (wherever relevant):

Does your plugin use the device location / uses an API that uses the device location?

Reproduction

I don't get any error once I build and run the app in debug/release mode.
only got the above mail from apple once I uploaded the app store

Additional Information

  • cordova-plugin-file-transfer version: 1.7.1
  • List of installed plugins:
    code-push 2.0.6 "CodePushAcquisition"
    com.elasticode.cordova 2.1.7 "Elasticode Cordova Plugin"
    com.etoro.chinaupdateplugin 13.0.0 "ChinaUpdatePlugin"
    cordova-android-support-gradle-release 2.0.1 "cordova-android-support-gradle-release"
    cordova-custom-config 5.0.2 "cordova-custom-config"
    cordova-plugin-app-version 0.1.9 "AppVersion"
    cordova-plugin-appsflyer-sdk 4.4.15 "AppsFlyer"
    cordova-plugin-code-push 1.11.13 "CodePush"
    cordova-plugin-customurlscheme 4.3.0 "Custom URL scheme"
    cordova-plugin-device 2.0.2 "Device"
    cordova-plugin-dialogs 2.0.1 "Notification"
    cordova-plugin-enable-multidex 0.1.3 "Enable Multidex"
    cordova-plugin-facebook4 4.2.1 "Facebook Connect"
    cordova-plugin-file 6.0.1 "File"
    cordova-plugin-file-transfer 1.7.1 "File Transfer"
    cordova-plugin-googleplus 5.3.2 "Google SignIn"
    cordova-plugin-inappbrowser 3.0.0 "InAppBrowser"
    cordova-plugin-intercom 6.2.0 "Intercom"
    cordova-plugin-network-information 2.0.2-dev "Network Information"
    cordova-plugin-splashscreen 5.0.2 "Splashscreen"
    cordova-plugin-statusbar 2.4.2 "StatusBar"
    cordova-plugin-wechat 2.6.0 "Wechat"
    cordova-plugin-whitelist 1.3.3 "Whitelist"
    cordova-plugin-zip 3.1.0 "cordova-plugin-zip"
    cordova-universal-links-plugin 1.2.1 "Universal Links Plugin"
    ionic-plugin-keyboard 2.2.1 "Keyboard"
    org.apache.cordova.inappbrowser 0.2.2 "InAppBrowser"
    phonegap-plugin-mobile-accessibility 1.0.4 "Mobile Accessibility"
    urbanairship-cordova 7.3.0 "Urban Airship
  • Cordova version: 7.0.0
  • iOS/Android/Windows version: 12
  • Does this reproduce on a debug build or release build? NO
  • Does this reproduce on a simulator, or only on a physical device? NO

IOS 13 Upload encounter Error Domain=NSCocoaErrorDomain Code=257

Bug Report

fileTransfer.upload(...) returns an error with code = 1. Works well with IOS 12.4.

Problem

While calling fileTransfer.upload() to upload a video,it return error code 1

code = 1;
source = "file:///private/var/mobile/Containers/Data/PluginKitPlugin/FABA3640-0F94-496D-94BC-85A8ED5241F6/tmp/trim.8466A661-EB72-45FC-9622-4E30AA1C1D3A.MOV";
target = "myService";

What is expected to happen?

Upload data with video successfully to a remote server.(Works well with IOS 12.4)

What does actually happen?

I found the problem is at this line.
NSData* fileData = [NSData dataWithContentsOfFile:filePath options:NSDataReadingMappedIfSafe error:&err];
Here's the error log

myapp[1222:123456] Error opening file file:///private/var/mobile/Containers/Data/PluginKitPlugin/FABA3640-0F94-496D-94BC-85A8ED5241F6/tmp/trim.8466A661-EB72-45FC-9622-4E30AA1C1D3A.MOV: Error Domain=NSCocoaErrorDomain Code=257 "The file “trim.8466A661-EB72-45FC-9622-4E30AA1C1D3A.MOV” couldn’t be opened because you don’t have permission to view it." UserInfo={NSFilePath=/private/var/mobile/Containers/Data/PluginKitPlugin/FABA3640-0F94-496D-94BC-85A8ED5241F6/tmp/trim.8466A661-EB72-45FC-9622-4E30AA1C1D3A.MOV, NSUnderlyingError=0x28199f2d0 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}}

It seems that apple change the way of dealing NSData

Information

I'm using xcode11 and complie to my IOS 13.1.2 device.

Command or Code

            fileTransfer.upload(_videoURL,  encodeURI(strServerURI), funUploadSuccess, captureError, _videoOption);

Environment, Platform, Device

Testing on iPhone8 with iOS version 12.3.2.
iPhoneX with iOS version 12.4.

Version information

MacOS Mojave 10.14.4
XCode 11
Cordova 9.0.0

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above

Dowload and open pdf file in device

i get pdf file from web service and i want to download it and open it in my android device.
using this code

fileTransfer.download(url,this.file.externalDataDirectory+ filename).then((entry) => {
this.localNotifications.schedule({
text: ‘Téléchargement de fichier’+filename+’ est terminé !!’,
led: ‘FF0000’,
sound: null
});

download the pdf file but connot open it because it has been saved as “error :invalid format” !!!with size 0.
any solution or suggestion please!

File Transfer HTTP Method

Is there any way to specify the HTTP method of the file transfer plugin?

I have this for my file upload:

        const options: FileUploadOptions = {
            fileKey: 'file',
            fileName: imageData.substr(imageData.lastIndexOf('/') + 1),
            headers: {},
            httpMethod: 'POST',
            chunkedMode: false,
            params: { action : 'INSERT', lineid : this.lineId }
        };

But it is being received as a GET request on my server side (PHP).

Downloaded PDF file disappears after few weeks

Bug Report

Problem

Downloaded files disappear after few weeks

What is expected to happen?

Downloaded files stay on the persistent storage permanently on both Android and iOS platforms.

What does actually happen?

Downloaded files are not found after several days or weeks.

Information

I have downloaded PDF files from a website and then store the locations of the filenames on the local storage. Then I use FileOpener plugin to open PDF files. After few weeks, the file-opener does not find some of the downloaded files and throws file not found error. I'm assuming the phone OS is removing the files for not being used frequently. I'm experiencing this issue for nearly 6 months or so. Please see the code snippet I use to download a pdf file.

Command or Code

private downloadPDF(pdf: IPdf, callback: (data) => void) {

const fileTransfer: FileTransferObject = this.transfer.create();

fileTransfer.download(pdf.Location, this.file.dataDirectory + pdf.Name).then((entry) => {

  if (this.platform.is('android')) {
    this.filePath.resolveNativePath(entry.toURL())
      .then(filePath => {
        callback(filePath);
      })
      .catch(err => console.log(JSON.stringify(err)));
  }
  else {
    callback(entry.toURL());
  }

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

}

Environment, Platform, Device

I'm using Ionic Framework version 3.
Platforms: Android and iOS

Version information

Ionic:

ionic (Ionic CLI) : 4.1.1
Ionic Framework : ionic-angular 3.6.0
@ionic/app-scripts : 3.1.8

Cordova:

cordova (Cordova CLI) : 8.1.2 ([email protected])
Cordova Platforms : android 6.4.0
Cordova Plugins : no whitelisted plugins (18 plugins total)

System:

Android SDK Tools : 26.1.1 (C:\Users[USERNAME]\AppData\Local\Android\sdk)
NodeJS : v6.11.3 (C:\Program Files\nodejs\node.exe)
npm : 6.5.0
OS : Windows 10

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above

Error 413: FileTransferError request entity too large

Specifically on iOS, I am getting a 413 error saying that the request entity is too large when I try and send a picture from my phone taken via camera. Depending on the image (obviously the size) it shows me this error, works at other times.

Has anyone experienced this and the best way to approach it?

Is there any way to compress the image file before uploading it with fileTransfer?

Any help or guidance would be appreciated.
Thanks

FileUploadOptions - timeout

Hi there,

Would you guys be able to reinstate this PR below?
#156

It'd be great if I could set the timeout for file uploads.
Perhaps an extra property to FileUploadOptions?

FileUploadOptions.timeout = (90*1000);
The timeout variable is to be specified in milliseconds.

I have an app where users might try to upload large files on the 3G/4G network.
Thank you very much in advance.

Cheers 😄 👍

can't abort while downloading

Bug Report

Problem

i am trying to cancel the downloads on using abort function.but abort fuction stays idle.

What is expected to happen?

when abort function is called it should abort the download!

What does actually happen?

abort function stays idle even if called

Command or Code

this.fileTransfer = this.transfer.create();
    this.fileTransfer.onProgress(ProgressEvent => {
      this._zone.run(() => {
        this.util.progressWidth =
          (ProgressEvent.loaded / ProgressEvent.total) * 100;
        // this.color = "#ff0000";
        this.util.progressPercent = Math.round(this.util.progressWidth);
        console.log("------", this.util.progressWidth, "----------");
        console.log("------", this.util.progressPercent, "----------");
      });
    });
// this.fileTransfer.abort();
    this.fileTransfer.download(url, this.dwfilePath + pdfname, true).then(
      entry => {
        //here logging our success downloaded file path in mobile.

        console.log("download completed: " + entry.toURL());
        this.entryurl=entry.toURL();
        this.modalController.dismiss(); 
        // this.openFile(entry.toURL());
      },
      error => {
        this.util.presentToast(
          this.translateService.instant(
            "chat.Download failed. Please try again."
          )
        );
        //here logging our error its easier to find out what type of error occured.
        this.modalController.dismiss();
        console.log("download failed: " + JSON.stringify(error));
      }
    );
  }
removedfile()
{
  console.log(this.filenames,"the pdf name in remove file")
  this.dwfilePath = this.file.externalRootDirectory;
  this.file.removeFile(this.dwfilePath,this.filenames)
  this.fileTransfer.abort();  
} 

Environment, Platform, Device

IN both Android and IOS

Version information

Ionic:

Ionic CLI : 6.0.1 (/usr/lib/node_modules/@ionic/cli)
Ionic Framework : @ionic/angular 4.11.10
@angular-devkit/build-angular : 0.13.9
@angular-devkit/schematics : 7.2.4
@angular/cli : 7.3.9
@ionic/angular-toolkit : 1.4.1

Cordova:

Cordova CLI : 9.0.0 ([email protected])
Cordova Platforms : android 8.1.0
Cordova Plugins : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 3.1.2, (and 41 other plugins)

Utility:

cordova-res : not installed
native-run : 0.3.0

System:

Android SDK Tools : 26.1.1 (/home/bsetec/Android/Sdk)
NodeJS : v10.14.0 (/usr/bin/node)
npm : 6.4.1
OS : Linux 3.13

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above

Windows 10 - unable to resolve path to module

I realize the plugin is deprecated, and I do plan to migrate to the new standard, however I wanted to ask about this in case there's an easy answer.

On Windows 10, I'm getting a few 'Unable to resolve path to module' errors inside FileTransferProxy.js.

Screenshot (7)

Thanks for any guidance.

Downloaded pdf files disappear after app rebuild on iOS platform

Bug Report

Problem

Downloaded PDF files disappear after an app rebuild on iOS platform

What is expected to happen?

Downloaded files stay on the persistent storage permanently on iOS platforms

What does actually happen?

Downloaded files are not found after an app rebuild on iOS platform.

Information

I have downloaded PDF files from a website and then store the locations of the filenames on the local storage. Then I use FileOpener plugin to open PDF files. Whenever I rebuild the app, the file-opener cannot find any of the files on iOS platform -on Android, it is fine. I'm experiencing this issue for nearly 6 months or so. It used to work before perfectly. Please see the code snippet I use to download a pdf file.

Command or Code

private downloadPDF(pdf: IPdf, callback: (data) => void) {

const fileTransfer: FileTransferObject = this.transfer.create();

fileTransfer.download(pdf.Location, this.file.dataDirectory + pdf.Name).then((entry) => {

  if (this.platform.is('android')) {
    this.filePath.resolveNativePath(entry.toURL())
      .then(filePath => {
        callback(filePath);
      })
      .catch(err => console.log(JSON.stringify(err)));
  }
  else {
    callback(entry.toURL());
  }

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

}

Environment, Platform, Device

I'm using Ionic Framework version 3.
Platforms: Android and iOS

Version information

Ionic:

ionic (Ionic CLI) : 4.1.1
Ionic Framework : ionic-angular 3.6.0
@ionic/app-scripts : 3.1.8

Cordova:

cordova (Cordova CLI) : 8.1.2 ([email protected])
Cordova Platforms : android 6.4.0
Cordova Plugins : no whitelisted plugins (18 plugins total)

System:

Android SDK Tools : 26.1.1 (C:\Users[USERNAME]\AppData\Local\Android\sdk)
NodeJS : v6.11.3 (C:\Program Files\nodejs\node.exe)
npm : 6.5.0
OS : Windows 10

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above

Erorr code 3 when download multiple files

Bug Report

When downloading with multiple instances of FileTransfer. Get Error code 3. Are multiple download not supported?

Problem

When downloading with multiple instances of FileTransfer. Get Error code 3. Are multiple download not supported?

What is expected to happen?

Multiple download of file happening at the same time.

What does actually happen?

The first file download fine. Second file get error code 3 in the return status.

Information

Command or Code

Environment, Platform, Device

Version information

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above

Android uploading image got error with code is 5

  • Bug Report
  • Feature Request
  • Support Question

Description

i uploaded an pic with android ,but i got an error width " { code: 5, message: ENCODING_ERR}", some pictures would got this error , but some not, why?

Command or Code

Environment, Platform, Device

Version information

Cordova: Cordova 9.0,
plugin: [email protected]
Other Frameworks: Ionic Framework 4

onprogress does not work on iOS when uploading file.

Bug Report

Problem

onprogress does not work on iOS when uploading file.Android success.

What is expected to happen?

onprogress return data when uploading file.

What does actually happen?

onprogress does not work when uploading file.

Information

Command or Code

import { FileTransfer, FileUploadOptions, FileTransferObject } from '@ionic-native/file-transfer';

@Injectable()
export class UploadService {

fileTransfer: FileTransferObject;

constructor(
private transfer: FileTransfer,
private config: Config,
private user: User
) {
this.fileTransfer = this.transfer.create();
}

// 执行文件上传
this.fileTransfer.upload(file.filePath, this.config.host + '/appProduct/document/upload' , options, false).then(
result => {
console.log('result');
}
).catch(
error => {
console.error(error);
}
);

this.fileTransfer.onProgress((progressEvent) => {
console.log('----progressEvent----',progressEvent)
});

}

Environment, Platform, Device

"cordova-plugin-file": "^4.3.3",
"cordova-plugin-file-transfer": "^1.6.3",
"ionic-angular": "^3.9.5",
"cordova-ios": "^4.4.0",

on iOS.

Version information

{
"name": "wzlApp",
"author": "Ionic Framework",
"homepage": "http://ionicframework.com/",
"private": true,
"scripts": {
"clean": "ionic-app-scripts clean",
"build": "ionic-app-scripts build",
"ionic:build": "ionic-app-scripts build",
"ionic:serve": "ionic-app-scripts serve"
},
"dependencies": {
"@angular/animations": "5.0.0",
"@angular/common": "5.0.0",
"@angular/compiler": "5.0.0",
"@angular/compiler-cli": "5.0.0",
"@angular/core": "5.0.0",
"@angular/forms": "5.0.0",
"@angular/http": "5.0.0",
"@angular/platform-browser": "5.0.0",
"@angular/platform-browser-dynamic": "5.0.0",
"@angular/platform-server": "5.0.0",
"@ionic-native/android-fingerprint-auth": "^4.20.0",
"@ionic-native/app-version": "3.12.1",
"@ionic-native/call-number": "3.12.1",
"@ionic-native/camera": "^4.0.0",
"@ionic-native/clipboard": "^4.3.2",
"@ionic-native/core": "^4.3.1",
"@ionic-native/device": "^4.20.0",
"@ionic-native/file": "^3.12.1",
"@ionic-native/file-transfer": "^4.20.0",
"@ionic-native/geolocation": "^4.20.0",
"@ionic-native/http": "^4.5.3",
"@ionic-native/image-picker": "^4.0.0",
"@ionic-native/in-app-browser": "^4.4.2",
"@ionic-native/keyboard": "^3.14.0",
"@ionic-native/media": "^4.20.0",
"@ionic-native/network": "^4.20.0",
"@ionic-native/photo-library": "^4.20.0",
"@ionic-native/qqsdk": "^4.20.0",
"@ionic-native/qr-scanner": "^4.20.0",
"@ionic-native/splash-screen": "3.12.1",
"@ionic-native/status-bar": "^4.5.3",
"@ionic-native/touch-id": "^4.20.0",
"@ionic-native/transfer": "^3.12.1",
"@ionic-native/zbar": "^4.3.2",
"@ionic/storage": "2.1.3",
"angular-svg-round-progressbar": "^1.1.0",
"call-number": "^1.0.1",
"com.synconset.imagepicker": "https://github.com/Telerik-Verified-Plugins/ImagePicker.git",
"cordova-android": "^6.2.3",
"cordova-android-support-gradle-release": "^3.0.0",
"cordova-browser": "^4.1.0",
"cordova-hot-code-push-plugin": "^1.5.3",
"cordova-ios": "^4.4.0",
"cordova-plugin-camera": "^2.4.1",
"cordova-plugin-compat": "^1.1.0",
"cordova-plugin-console": "~1.0.5",
"cordova-plugin-crosswalk-webview": "^2.3.0",
"cordova-plugin-cszbar": "^1.3.4",
"cordova-plugin-device": "~1.1.4",
"cordova-plugin-file": "^4.3.3",
"cordova-plugin-file-transfer": "^1.6.3",
"cordova-plugin-http": "^1.2.0",
"cordova-plugin-inappbrowser": "^1.7.2",
"cordova-plugin-ionic-webview": "^1.1.16",
"cordova-plugin-network-information": "^1.3.3",
"cordova-plugin-splashscreen": "~4.0.1",
"cordova-plugin-statusbar": "^2.4.1",
"cordova-plugin-telerik-imagepicker": "git+https://github.com/Telerik-Verified-Plugins/ImagePicker.git",
"cordova-plugin-whitelist": "~1.3.1",
"cordova-sqlite-storage": "^2.0.4",
"ionic-angular": "^3.9.5",
"ionic-image-loader": "^3.2.1",
"ionic-plugin-keyboard": "~2.2.1",
"ionicons": "3.0.0",
"mx.ferreyra.callnumber": "~0.0.2",
"rxjs": "5.5.2",
"sw-toolbox": "3.6.0",
"zone.js": "0.8.18"
},
"devDependencies": {
"@ionic/app-scripts": "3.1.0",
"cordova": "^6.5.0",
"cordova-sqlite-storage-dependencies": "^1.0.3",
"http-proxy-middleware": "^0.17.3",
"typescript": "2.4.2"
},
"cordovaPlugins": [
"cordova-plugin-whitelist",
"cordova-plugin-console",
"cordova-plugin-device",
"cordova-plugin-splashscreen",
"ionic-plugin-keyboard"
],
"cordovaPlatforms": [],
"description": "myApp: An Ionic project",
"cordova": {
"plugins": {
"cordova-plugin-console": {},
"cordova-plugin-device": {},
"cordova-plugin-splashscreen": {},
"cordova-plugin-whitelist": {},
"ionic-plugin-keyboard": {},
"cordova-plugin-crosswalk-webview": {
"XWALK_VERSION": "23+",
"XWALK_LITEVERSION": "xwalk_core_library_canary:17+",
"XWALK_COMMANDLINE": "--disable-pull-to-refresh-effect",
"XWALK_MODE": "embedded",
"XWALK_MULTIPLEAPK": "true"
},
"phonegap-plugin-push": {},
"mx.ferreyra.callnumber": {},
"cordova-plugin-file": {},
"cordova-plugin-file-transfer": {},
"cordova-plugin-camera": {
"CAMERA_USAGE_DESCRIPTION": " ",
"PHOTOLIBRARY_USAGE_DESCRIPTION": " "
},
"com.synconset.imagepicker": {
"PHOTO_LIBRARY_USAGE_DESCRIPTION": "为了能够使您正常上传文件"
},
"cordova-sqlite-storage": {},
"cordova-clipboard": {},
"cordova-plugin-network-information": {},
"cordova-plugin-cszbar": {},
"cordova-plugin-inappbrowser": {},
"cordova-plugin-http": {},
"cordova-hot-code-push-plugin": {},
"PALink": {},
"cordova-plugin-statusbar": {},
"cordova-plugin-ionic-webview": {},
"cordova-android-support-gradle-release": {
"ANDROID_SUPPORT_VERSION": "27.0.0"
}
},
"platforms": [
"android",
"browser",
"ios"
]
}
}

  • [x ] I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • [ x] I included all the necessary information above

chunk file slice upload

Feature Request

Motivation Behind Feature

i want upload large file,more then 1Gb

Feature Description

need support slice file to upload? can you help me

Alternatives or Workarounds

Downloaded file got in 0 Bytes

Using Ionic 3.20.1 and node 10.16.3
android platform
let uri = 'server url using https';
let dir = this.file.externalRootDirectory+'AppName/Documents/';
this.platform.ready().then(() => {
const fileTransfer: FileTransferObject = this.transfer.create();
fileTransfer.download(uri,dir+'filename.pdf').then((entry: Entry) => {
var fileEntry = entry as FileEntry;
console.log(fileEntry);
}, (error) => {
});
});

My file has been downloaded but got 0 Bytes size
I don't know what happen?
i am using these versions
"@ionic-native/file": "^4.20.0",
"@ionic-native/file-chooser": "^4.18.0",
"@ionic-native/file-opener": "^4.20.0",
"@ionic-native/file-path": "^4.20.0",
"@ionic-native/file-picker": "^4.18.0",
"@ionic-native/file-transfer": "^4.20.0",
Please help

Media scanner after download file

Feature Request

Motivation Behind Feature

Media Scanner scans the entire phone for any media files like songs, photos and videos. Once the process finishes, photos, songs and videos show up on the gallery so you can easily see them.

Feature Description

After i have finished downloading media or capturing the image and video file on my app . The media doesn't shows in gallery as image or video . So i have to restart my app then media will shows in gallery . So i have feature request to add media scanner After capturing or downloading media without restarting phone .

After Uploading(both success / fail) Page routes to Previous Screen.

Bug Report

Problem

Uploading an Image from Camera or Gallery using ionic Camera plugin (works fine) but Application routes to previous Screen Automatically on both cases(success / failure).

What is expected to happen?

Expectation: Application should remain on same page.

What does actually happen?

Application going to previous page after uploading image taken from ionic Camera plugin V 4.1.0 (on both cases success / fail)

Information

ionic v 5.2.1
cordova v 9.0.0 ([email protected])

Plugin Versions:

cordova-plugin-camera 4.1.0 "Camera"
cordova-plugin-file 6.0.2 "File"
cordova-plugin-file-transfer 1.7.1 "File Transfer"

Command or Code

ionic start testProject blank
ionic cordova plugin add cordova-plugin-file
ionic cordova plugin add cordova-plugin-camera
ionic cordova plugin add cordova-plugin-file-transfer

Environment, Platform, Device

Ionic:

Ionic CLI : 5.2.1 (C:\Users\ammar\AppData\Roaming\npm\node_modules\ionic)
Ionic Framework : @ionic/angular 4.6.2
@angular-devkit/build-angular : 0.13.9
@angular-devkit/schematics : 7.3.9
@angular/cli : 7.3.9
@ionic/angular-toolkit : 1.5.1

Cordova:

Cordova CLI : 9.0.0 ([email protected])
Cordova Platforms : android 8.0.0
Cordova Plugins : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 4.1.1, (and 13 other plugins)

Utility:

cordova-res : 0.5.1
native-run : 0.2.7

System:

Android SDK Tools : 26.1.1 (C:\Users\ammar\AppData\Local\Android\Sdk)
NodeJS : v10.15.3 (C:\Program Files\nodejs\node.exe)
npm : 6.11.3
OS : Windows 10

Version information

Stackoverflow Link for code:

Stackoverflow Question link

Checklist

  • [x ] I searched for existing GitHub issues
  • [x ] I updated all Cordova tooling to most recent version
  • [x ] I included all the necessary information above

File Upload Order Issue

Is it a way to upload images in a certain order. Currently the files being uploaded are in random order. I want to upload them in first in first out order

Apache Cordova uses GitHub Issues as a feature request and bug tracker only.
For usage and support questions, please check out the resources below. Thanks!


You can get answers to your usage and support questions about Apache Cordova on:


If you are using a tool that uses Cordova internally, like e.g. Ionic, check their support channels:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.