79759343

Date: 2025-09-08 21:19:50
Score: 0.5
Natty:
Report link

I have finally managed to share via whatsapp the two types of files I needed to: png images and gpx (xml) files. You have to bear in mind that the method is probably not universal and may not work for certain files. In both cases, I first saved the file to the external cache folder using capacitor's filesystem:

      const savedFile = await Filesystem.writeFile({
        path: file,       
        data: gpxText,
        directory: Directory.ExternalCache,
        recursive: true,
        encoding: Encoding.UTF8,
      });

Then, I share the file URI using Cordova's Social Sharing.

      await this.socialSharing.shareWithOptions({
        files: [savedFile.uri],
        chooserTitle: '...'
      });

However, in the case of the gpx file, you can send just the file, without any text. If you try to send both text and file, the transfer fails. ChatGPT suggests that this may be due to the following:

  1. Some sharing plugins (cordova-plugin-x-socialsharing, Capacitor Share API, etc.) treat a text + file share differently than a file-only share.

  2. On Android, if you only provide a file (with a valid MIME type, e.g. application/gpx+xml or application/octet-stream), the system share sheet is more likely to open correctly and show WhatsApp.

  3. When you add a message or text, certain apps (like WhatsApp) may try to interpret the share as a text-only share, which then hides the file.

Reasons:
  • Blacklisted phrase (0.5): I need
  • Long answer (-1):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Enric Terradellas