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

File Write with Capacitor not possible #1831

Closed
hendriknitsche opened this issue Oct 5, 2023 · 2 comments
Closed

File Write with Capacitor not possible #1831

hendriknitsche opened this issue Oct 5, 2023 · 2 comments
Labels

Comments

@hendriknitsche
Copy link

          I am doing an workaround for now by sharing immediately after writing the file to `Directory.Cache`. At least the users will be able to share the files in a persistent place.
import { Filesystem, Directory, Encoding, FilesystemPlugin, WriteFileOptions } from '@capacitor/filesystem';
import { Share } from '@capacitor/share';

public async saveFile(data: string, fileNameWithExtension: string, type: string): Promise<boolean> {

  // Browser
  if (this._platform.is('mobileweb') || this._platform.is('desktop')) {
    const blob = new Blob([data], { type });
    this._saveFileBrowser(blob, fileNameWithExtension);
    return true;
  }

  // Native
  try {
    const fileConfig: WriteFileOptions = {
      path: `Exports/${fileNameWithExtension}`,
      data: data,
      directory: Directory.Cache,
      encoding: Encoding.UTF8,
      recursive: true
    };
    const writeFileResult = await this._nativeFileSystem.writeFile(fileConfig);
    await this._nativeShare.share({ url: writeFileResult.uri });

    return true;
  }
  catch (error) {
    console.error("Error creating file: ", JSON.stringify(error));
    return false;
  }
}

Need a fix asap!

Originally posted by @abdunnahid in #1512 (comment)


I tried this but I receive:

Error: "Share" plugin is not implemented on android.

How can I solve this? Or how can I save a File on Android with capacitor?

@ionitron-bot ionitron-bot bot added the triage label Oct 5, 2023
@jcesarmobile
Copy link
Member

please, create a proper report filling the whole template and provide a sample app instead of creating the issue from a comment that is not related to your own problem.

common causes of plugin not implemented are described here
https://capacitorjs.com/docs/android/troubleshooting#plugin-not-implemented

@jcesarmobile jcesarmobile closed this as not planned Won't fix, can't repro, duplicate, stale Oct 5, 2023
@ionitron-bot
Copy link

ionitron-bot bot commented Oct 20, 2023

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of the plugin, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Oct 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants