Coder Social home page Coder Social logo

alwaysloveme / capacitor-plugin-filedownload Goto Github PK

View Code? Open in Web Editor NEW
13.0 13.0 6.0 368 KB

a file download plugin for Capacitor3.0+

License: MIT License

JavaScript 14.94% Ruby 3.54% Java 42.36% CSS 0.15% HTML 3.86% TypeScript 12.19% Swift 20.19% Objective-C 2.77%

capacitor-plugin-filedownload's Introduction

yoyo930021

Hi, I am ZX πŸ‘‹

A Front-end developer from ShangHai of ✨China✨

React angular Vue.js Ionic NestJs TypeScript

capacitor-plugin-filedownload's People

Contributors

alwaysloveme avatar ghenry22 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

capacitor-plugin-filedownload's Issues

file can not be open in android

file:///storage/emulated/0/Android/data/com.aaa.ca/files/demo.pdf

file opener cannot open file (it always shown error file can not be open)

destination 'DOCUMENT' is not working

its working on iphone 13

don't change Http method to POST just because I add headers

Your documentation states that if I add headers you will change the http method from PUT to POST.

In your Android source you don't do that, in your iOS source you do. I believe the Android source is correct, and iOS is a bug - and it should only switch if you add a BODY; although I would perhaps suggest that you also give the user an option to specify what HTTP method they would like to use instead.

Reason being: I need to do a GET for my file, but I also need to add some headers for authorization, and some others things (changing the method is not an option). By adding this you switch the method to a POST which will fail. Plus as I stated above your Android and iOS behaviours differ.

From your Java source - note only changed based on the fact there is a body.

JSObject requestBodyObject = call.getObject("body", null);
if (requestBodyObject != null) {
  // code removed for clarity
  requestBuilder.method("POST", requestBody);
}

From your swift source - note changed even if I add a header

let method = !headers.isEmpty || body != nil ? HTTPMethod.post : HTTPMethod.get

Make destination type string

Instead of trying to map to specific folders for destination make it type string and accept a file path.

this way people can use capacitor file system plugin to get the base path (data, documents etc) and can add on their own sub folder if wanted.

filename just specifies the destination filename and you concat the 2 values to get the file path to save to.

you could add a check to make sure that destination exists before trying to download and reject if not.

File not appearing in gallery / file manager

I am downloading Images and videos, but files are not appearing in Gallery or File Manager:

response:

{
    "success": true,
    "path": "file:///storage/emulated/0/Android/data/com.company.appName/files/gallery-20230908040438_1694189077018.png"
}

Code:


writeFile = async (url: string) => {
    let parts = url.split('/');
    let name = parts[parts.length - 1];
    await FileDownload.download({
      url: url,
      fileName: name,
      headers: {},
      body: {},
      downloadTitle: 'downloading',
      downloadDescription: 'file is downloading',
      destination: 'DOCUMENT'
    }).then(async (res) => {
      console.log(res)
    }).catch(err => {
      console.log(err);
    })
  }

Storage permission popup response is ignored on Android

Hello, I am downloading a file on my application. It works perfectly, the file is downloaded and I can find it into files folders of ExternalStorage (cf screenshot 1).
But when I came back to the application there is a popup asking for storage permission. Is it normal behaviour to be able to download the file even if the result of the popup has not yet been answered? (cf screenshot 2)

Is there a way to handle the answer of the popup to prevent the downloading if the user refuses App to access storage ?

Tested : on Android 6.0.1 (Galaxy S5) and Android 12 (Pixel 3)

Screenshot_2023-05-25-17-26-51
Screenshot_2023-05-25-17-25-04

destination=EXTERNAL_STORAGE doesn't save the downloaded file

I'm having trouble getting files to download onto external storage on my Pixel 3a running Android 12. If I set destination=LIBRARY, the files go into the standard Downloads folder with no problems. But if I set destination=EXTERNAL_STORAGE and plug a USB drive into my phone (via a USB-OTG adapter), I get this error:

Error: download fail: /storage/emulated/0/img00001.jpg: open failed: EPERM (Operation not permitted)

I have granted my Ionic app permission to access "File and media". Is there another permission that needs approval for external storage?

Also, does the filedownload plugin support web apps? I've tried running "ionic serve" and launching the app in Chrome, but the HTTP download request is never sent. No error is thrown, the download() function just return the object {"path":""}. I'm guessing the plugin doesn't support PWAs, but just wanted to make sure.

Access downloaded files / specify the path of the downloaded file

So the package works fine, but it downloads my file (without being able to select the path) to /storage/emulated/0/Android/data/{appId}/files/{fileName}

How can I open this file instantly, or how can I make the plugin download the files to the Download folder of the device?

I'm trying to use the package to download .apk files (app updates) and install them.

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.