Giter VIP home page Giter VIP logo

cordova-plugin-downloader's Introduction

Provided for reference only - not actively being maintained. Please fork if it's useful

cordova-plugin-downloader

Cordova plugin to download, store and unzip files with no cordova-file-transfer dependency. cordova-file-transfer was recently depreciated.

Inspired by cordova-plugin-fastrde-downloader but with less features.

Compatibility

  • Android 4.4+
  • iOS 10+
  • Cordova 5.0+

Installation

cordova plugin add cordova-plugin-downloader

This will also install cordova-plugin-file and cordova-plugin-zip if not already installed.

Basic Usage

var dl = new download();

dl.Initialize({
    fileSystem : cordova.file.dataDirectory,
    folder: "code",
    unzip: true,
    remove: true,
    timeout: 0,
    success: DownloaderSuccess,
    error: DownloaderError,
    headers: [
        {
            Key: 'Authorization',
            Value: 'Basic ' + btoa(token)
        }
    ]
});


dl.Get("https://www.yourdomain.com/somezipfile.zip");

function DownloaderError(err) {
    console.log("download error: " + err);
    alert("download error: " + err);
}

function DownloaderSuccess() {
    console.log("yay!");
}

Initialization

key default description
fileSystem cordova.file.dataDirectory Cordova filesystem root to work in. More details here
folder folder Directory within fileSystem to store downloaded file and unzip. Created if doesn't exist
unzip false Set true to attempt to unzip the downloaded file
remove false Set true to remove the zip file after unzipping
timeout 0 Download timeout in milliseconds. Set to 0 for infinite time
success undefined Success callback
error undefined Error callback. Argument indicates problem
headers [] Set XHR Headers. Accepts a list of Key/Value pairs. [{Key: 'Authorization', Value: 'Basic xxxxxxx'}]

Error Codes

code description
0 Cannot resolve filesystem
1 download.Get supported on Cordova only
2 Cannot create destination folder
3 Transfer error
4 Abort
5 Network error
6 Timeout
7 File create error
8 File write error
9 UNZIP error
10 Delete error #1
11 Delete error #2

Troubleshooting

Chrome / Safari debugging reveals many basic problems but if this isn't sufficient suggest adb logcat for Android and Xcode Window->Devices and Simulators for iOS. Example Android with filter for app com.yourco.yourapp:

macOS / Linux:

adb logcat | grep `adb shell ps | grep com.yourco.yourapp | cut -c10-15`

Windows (assumes you have grep somewhere in your Windows path):

for /F %i in ('adb shell "ps|grep com.yourco.yourapp|cut -c10-15"') do set ANPID=%i&adb logcat|grep %ANPID%

...where com.yourco.yourapp is your App's package name.

cordova-plugin-downloader's People

Contributors

benjaminmwilson avatar thembani avatar thembanifubesi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

cordova-plugin-downloader's Issues

plugin doesn't work

Greetings
I am trying to make this plugin work in my app but it does nothing I have dis ejected the script I used, I have done nothing but copy paste modifying only uri and folder:

`
var dl = new download();

dl.Initialize({
    fileSystem: cordova.file.dataDirectory,
    folder: "Download",
    unzip: true,
    remove: true,
    timeout: 0,
    success: DownloaderSuccess,
    error: DownloaderError,
    headers: [{
        Key: 'Authorization',
        Value: 'Basic ' + btoa(token)
    }]
});


dl.Get("https://www.radiomatese.it/Download/RadioMatese.apk");

function DownloaderError(err) {
    console.log("download error: " + err);
    alert("download error: " + err);
}

function DownloaderSuccess() {
    navigator.app.exitApp();
}

`

It does absolutely nothing

Downloaded file (application/octet-stream) is of 0 bytes.

Dear Concern,

I am using your plugin, it works well on images with direct link. However, when I am trying to download a image file or a file having mime type of 'application/octate-stream' , the file is created, but not downloaded. It is showing 0 bytes as its file size.

The file I was trying to download: https://firebasestorage.googleapis.com/v0/b/brilliant-inferno-7571.appspot.com/o/albums%2Fprofile_photos%2F1602636386448?alt=media&token=e810cd88-faf1-4d99-86da-34e9daef74b0 (Didn't work)

But this file was downloaded perfectly: https://www.google.com.bd/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png

Please assist me to get rid of this issue.

Thanks in advance!

CORS issue

Hello there, i'm trying to use it but every file that i tried to download, get this CORS error:

Access to XMLHttpRequest at 'https://conteudo.imguol.com.br/c/entretenimento/c4/2018/05/15/super-mario-odyssey-1526426783086_v2_1170x540.jpgx' from origin 'http://localhost:8080' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Download image to library / camera roll

I try download png/jpg to camera roll but not work, image not appear in gallery

var dl = new download();

dl.Initialize({
    fileSystem : cordova.file.dataDirectory,
    folder: "code",
    unzip: false,
    remove: false,
    timeout: 0,
    success: DownloaderSuccess,
    error: DownloaderError
});


dl.Get("https://ptkdev.it/img/ptkdev_patryk_rzucidlo_avatar_1024.png");

function DownloaderError(err) {
    console.log("download error: " + err);
    alert("download error: " + err);
}

function DownloaderSuccess() {
    alert("Done!");
}

Plugin conflicts

I am trying to use this plugin today but there seem to be conflicts with another plugin that prevent an iOS build (I haven't tried Android yet). Here is my list of current plugins:

    "cordova-plugin-add-swift-support": "1.7.2",
    "cordova-plugin-advanced-http": "2.1.1",
    "cordova-plugin-app-version": "0.1.9",
    "cordova-plugin-appavailability": "0.4.2",
    "cordova-plugin-ble": "2.0.1",
    "cordova-plugin-camera": "4.1.0",
    "cordova-plugin-compat": "1.2.0",
    "cordova-plugin-device": "2.0.3",
    "cordova-plugin-dialogs": "2.0.2",
    "cordova-plugin-downloader": "0.0.4",
    "cordova-plugin-eddystone": "1.3.0",
    "cordova-plugin-email": "1.2.7",
    "cordova-plugin-file": "6.0.2",
    "cordova-plugin-file-hash": "0.4.1",
    "cordova-plugin-fullscreen": "1.2.0",
    "cordova-plugin-geofence": (using a copy, location confidential)
    "cordova-plugin-geolocation": "4.0.2",
    "cordova-plugin-google-analytics": "1.8.6",
    "cordova-plugin-inappbrowser": (using a copy, location confidential)
    "cordova-plugin-inapppurchase": "1.2.0",
    "cordova-plugin-ionic-keyboard": "2.1.3",
    "cordova-plugin-ionic-webview": "4.1.1",
    "cordova-plugin-iroot": "0.8.0",
    "cordova-plugin-network-information": "2.0.2",
    "cordova-plugin-screen-orientation": "3.0.2",
    "cordova-plugin-secure-storage": "3.0.2",
    "cordova-plugin-splashscreen": "5.0.3",
    "cordova-plugin-statusbar": "2.4.3",
    "cordova-plugin-vibration": "3.1.1",
    "cordova-plugin-whitelist": "1.3.4",
    "cordova-plugin-x-socialsharing": "5.4.7",
    "cordova-plugin-zip": "^3.1.0",
    "cordova.plugins.diagnostic": "5.0.0",
    "ionic-plugin-deeplinks": "1.0.20",
    "phonegap-plugin-contentsync": "1.4.2",
    "phonegap-plugin-multidex": "1.0.0",
    "phonegap-plugin-push": "2.2.3"

Here is my app system info:

Ionic:

   Ionic CLI                     : 5.2.3
   Ionic Framework               : @ionic/angular 4.6.2
   @angular-devkit/build-angular : 0.801.2
   @angular-devkit/schematics    : 8.1.2
   @angular/cli                  : 8.1.2
   @ionic/angular-toolkit        : 2.0.0

Cordova:

   Cordova CLI       : 8.1.2 ([email protected])
   Cordova Platforms : ios 5.0.1
   Cordova Plugins   : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 4.1.1, (and 31 other plugins)

Utility:

   cordova-res : not installed
   native-run  : 0.2.7 (update available: 0.2.8)

System:

   Android SDK Tools : 26.1.1 (/Users/rc101077/Library/Android/sdk)
   ios-deploy        : 1.9.4
   ios-sim           : 8.0.2
   NodeJS            : v10.16.0 (/Users/rc101077/.nvm/versions/node/v10.16.0/bin/node)
   npm               : 6.9.0
   OS                : macOS Mojave
   Xcode             : Xcode 10.3 Build version 10G8

Ionic iOS build error:

ld: 64 duplicate symbols for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

** BUILD FAILED **


The following build commands failed:
        Ld build/emulator/FooBar.app/FooBar normal x86_64
(1 failure)
xcodebuild: Command failed with exit code 65

Can you provide any insights as to the conflicts?

--Russ

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.