6c65726f79 / capacitor-filesharer

Capacitor plugin to download and share files for the Web, Android and iOS! Show your appreciation with a Github ★

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Capacitor plugin for file sharing

npm npm Twitter Follow Donate

Installation

npm i @byteowls/capacitor-filesharer

Minimum Capacitor version is 2.0.0

Configuration

This example shows the common process of configuring this plugin.

Although it was taken from a Angular 6 application, it should work in other frameworks as well.

Use it

import {
  FileSharer
} from '@byteowls/capacitor-filesharer';

@Component({
  template: '<button (click)="downloadButtonClick()">Download file</button>'
})
export class SignupComponent {
    downloadButtonClick() {
        FileSharer.share({
            filename: "test.pdf",
            base64Data: "...",
            contentType: "application/pdf",
        }).then(() => {
            // do sth
        }).catch(error => {
            console.error("File sharing failed", error.message);
        });
    }
}

Error Codes

  • ERR_PARAM_NO_FILENAME ... Filename missing or invalid.
  • ERR_PARAM_NO_DATA ... Base64 data missing.
  • ERR_PARAM_NO_CONTENT_TYPE ... Content type missing
  • ERR_PARAM_DATA_INVALID ... Base64 data is invalid. See this comment for a possible error.
  • ERR_FILE_CACHING_FAILED ... Caching the file in temp directory on the device failed.

Platform: Web/PWA

No further config is needed.

Platform: Android

Register the plugin in com.companyname.appname.MainActivity#onCreate

import com.byteowls.capacitor.filesharer.FileSharerPlugin;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        List<Class<? extends Plugin>> additionalPlugins = new ArrayList<>();
        // Additional plugins you've installed go here
        // Ex: additionalPlugins.add(TotallyAwesomePlugin.class);
        additionalPlugins.add(FileSharerPlugin.class);

        // Initializes the Bridge
        this.init(savedInstanceState, additionalPlugins);
    }

Override the onSaveInstanceState on the main activity to avoid an issue that results in !!! FAILED BINDER TRANSACTION !!! errors when dealing with larger files (Related issue)

  @Override
  public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.clear();
  }

Platform: iOS

No further config is needed. On iOS the plugin is registered automatically by Capacitor.

Platform: Electron

  • No timeline.

Contribute

See Contribution Guidelines.

Changelog

See CHANGELOG.

License

MIT. Please see LICENSE.

BYTEOWLS Software & Consulting

This plugin is powered by BYTEOWLS Software & Consulting and was build for Team Conductor - Next generation club management platform.

About

Capacitor plugin to download and share files for the Web, Android and iOS! Show your appreciation with a Github ★

License:MIT License


Languages

Language:Java 53.8%Language:TypeScript 15.6%Language:Swift 15.0%Language:Ruby 7.2%Language:Objective-C 6.7%Language:JavaScript 1.8%