capacitor-plugins icon indicating copy to clipboard operation
capacitor-plugins copied to clipboard

feat: add `file-transfer` plugin

Open robingenz opened this issue 2 years ago • 12 comments

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 https://github.com/ionic-team/capacitor/issues/5964

robingenz avatar Apr 09 '23 09:04 robingenz

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

Tragio avatar Apr 19 '23 11:04 Tragio

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

muuvmuuv avatar Jul 19 '23 09:07 muuvmuuv

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

robingenz avatar Jul 19 '23 09:07 robingenz

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.

muuvmuuv avatar Jul 19 '23 09:07 muuvmuuv

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.

robingenz avatar Jul 19 '23 09:07 robingenz

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)
  })
}

muuvmuuv avatar Jul 19 '23 10:07 muuvmuuv

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

SchneMa avatar Jul 19 '23 12:07 SchneMa

@SchneMa ETA is next month.

robingenz avatar Jul 19 '23 14:07 robingenz

Any news on this?

coderpradp avatar Oct 07 '23 18:10 coderpradp

Any news on this?

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

robingenz avatar Oct 07 '23 18:10 robingenz

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

lsolano2707 avatar Mar 07 '24 04:03 lsolano2707

@lsolano2707 A few plugins are:

But this plugin is not yet available.

robingenz avatar Mar 07 '24 10:03 robingenz