Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add file-transfer plugin #24

Open
robingenz opened this issue Apr 9, 2023 · 12 comments
Open

feat: add file-transfer plugin #24

robingenz opened this issue Apr 9, 2023 · 12 comments
Labels
feature Feature request

Comments

@robingenz
Copy link
Member

Is your feature request related to a problem? Please describe:

Currently there is no Capacitor 4 compatible plugin that can be used to upload and download files.

Describe the solution you'd like:

Create a plugin that allows you to upload and download files.

Describe alternatives you've considered:

Additional context:

Related to ionic-team/capacitor#5964

@robingenz robingenz added the feature Feature request label Apr 9, 2023
@Tragio
Copy link

Tragio commented Apr 19, 2023

@robingenz there is this plugin https://github.com/AlwaysLoveme/capacitor-plugin-filedownload not sure if can help or contribute to it.

@muuvmuuv
Copy link

Capacitor Filesystem will soon be able to download files and Http has been updated to handle FormData and files in FormData.

@robingenz
Copy link
Member Author

This plugin will offer advanced features. That is why it is still on the roadmap, at least for now.

@muuvmuuv
Copy link

Cool! Then I will add my "request" for an advanced-feature: progress event callback for each download instead/(additionally) of a listener on all request (like it is with the current implementation by Ionic-Team).

Our use-case is a download-widget which downloads >1800 files in parallel in batches and I would like to have a proper kb/s and estimated time progress in it. Our current implementation works but it requires to cache the url and loaded bytes in a Set and other hacky stuff to make it work.

@robingenz
Copy link
Member Author

My current implementation (Android is done, iOS & Web is pending) also uses a listener for all uploads/downloads, but instead of using url to identify a request, I currently use a unique requestId.
I may change this. There are of course more features to come. Be prepared and subscribe to the issue!
Feel free to let me know if you have more ideas.

@muuvmuuv
Copy link

Ah, great, that would work a little better if it is returned with each event.

Just sharing my listener here for anyone looking for that:

Http download listener
private createHttpListener() {
  return Filesystem.addListener("progress", ({ url, bytes, contentLength }) => {
    const progress = new DownloadProgress(
      this.remaining,
      this.bytesTotal,
      this.bytesLoaded,
      contentLength,
    )

    if (!url.includes("your-domain.")) {
      // Files coming from other servers have no file size so we need to get that
      // value during file download.
      if (contentLength === 0) {
        // Some servers do not respond with a content length.
        this.event.downloadProgressChange.next(progress)
        return
      }
      if (!this.previousBytes.has(url)) {
        this.bytesTotal += contentLength
        this.previousBytes.set(url, 0)
      }
    }

    this.bytesLoaded += bytes - (this.previousBytes.get(url) || 0)
    this.previousBytes.set(url, bytes)

    this.event.downloadProgressChange.next(progress)
  })
}

@SchneMa
Copy link

SchneMa commented Jul 19, 2023

Are there any infos when or in which version Upload/Download will be available?

@robingenz
Copy link
Member Author

@SchneMa ETA is next month.

@coderpradp
Copy link

Any news on this?

@robingenz
Copy link
Member Author

robingenz commented Oct 7, 2023

Any news on this?

I prioritized the development of another plugin for a sponsor (see capawesome-team/capacitor-firebase#434). Therefore, the development of this plugin has been postponed.

@lsolano2707
Copy link

Any news?, I want to upload large files (videos) with capacitor without Ionic and I read "The File Handling Guide for Capacitor" and here mentions that there are plugins to upload files directly to server but I have no idea what they are

@robingenz
Copy link
Member Author

@lsolano2707 A few plugins are:

But this plugin is not yet available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Feature request
Projects
None yet
Development

No branches or pull requests

6 participants