@capacitor/share - there is not possible to share vcard by gmail #2460
Copy link
Copy link
Open
Labels
Description
Bug Report
Plugin(s)
@capacitor/share - 8.0.0
Capacitor Version
Latest Dependencies:
@capacitor/cli: 8.0.0
@capacitor/core: 8.0.0
@capacitor/android: 8.0.0
@capacitor/ios: 8.0.0
Installed Dependencies:
@capacitor/cli: 8.0.0
@capacitor/core: 8.0.0
@capacitor/android: 8.0.0
@capacitor/ios: 8.0.0
Platform(s)
iOS
Current Behavior
I am creating vcard info for sharing. The code work well for most cases but when I want to share .vcf file by Gmail or Slack, it tells me "The files you are trying to attach are invalid."
Expected Behavior
Possible to share vcard file by Gmail and Slack
Code Reproduction
if (!text) return '';
return text
.replace(/\\/g, '\\\\')
.replace(/\n/g, '\\n')
.replace(/,/g, '\\,')
.replace(/;/g, '\\;');
}
toAsciiFileName(s: string) {
return (s || '')
.normalize('NFD')
.replace(/[\u0300-\u036f]/g, '')
.replace(/[^a-zA-Z0-9_-]/g, '_');
}
generateVCard(contact: {
firstName: string;
lastName: string;
phone?: string;
email?: string;
organization?: string;
address?: string;
website?: string;
}): string {
const lines: string[] = [];
lines.push('BEGIN:VCARD');
lines.push('VERSION:3.0');
const lastName = this.escapeVCard(contact.lastName);
const firstName = this.escapeVCard(contact.firstName);
lines.push(`N:${lastName};${firstName};;;`);
lines.push(`FN:${firstName} ${lastName}`.trim());
if (contact.organization) {
lines.push(`ORG:${this.escapeVCard(contact.organization)}`);
}
if (contact.phone) {
lines.push(`TEL;TYPE=CELL:${this.escapeVCard(contact.phone)}`);
}
if (contact.email) {
lines.push(`EMAIL;TYPE=INTERNET:${this.escapeVCard(contact.email)}`);
}
if (contact.address) {
const addressParts = contact.address.split(';');
const escapedParts = addressParts.map(part => this.escapeVCard(part));
lines.push(`ADR;TYPE=HOME:;;${escapedParts.join(';')}`);
}
if (contact.website) {
lines.push(`URL:${this.escapeVCard(contact.website)}`);
}
lines.push('END:VCARD');
return lines.join('\r\n') + '\r\n';
}
async contactShare(): Promise<void> {
if (!this.vcardValue) return;
const safeFirst = this.toAsciiFileName(this.firstname);
const safeLast = this.toAsciiFileName(this.lastname);
const fileName = `${safeFirst || 'Contact'}_${safeLast || 'VCard'}.vcf`;
const dir = Directory.Documents;
await Filesystem.writeFile({path: fileName, data: this.vcardValue, directory: dir, encoding: Encoding.UTF8});
const {uri} = await Filesystem.getUri({directory: dir, path: fileName});
await Share.share({
title: `${this.firstname} ${this.lastname}`.trim(),
dialogTitle: 'Share contact',
files: [uri],
});
}
Other Technical Details
Additional Context
Reactions are currently unavailable
Activity
OS-pedrogustavobilro commentedon Feb 18, 2026
Hey @cihakmar, thanks for opening the issue. I've create this app to reproduce the issue https://github.com/OS-pedrogustavobilro/capacitor-plugins-issue2460-share, I've reproduced it on iOS trying to share a vcard to Gmail, and I get that error "The files that you are trying to attach are invalid". I'm not getting an equivalent error when sharing the the apple Mail app, so there should be some difference in how some applications receive certain files.
I'm not sure yet if this is something that can be fixed in the plugin, a deeper investigation is required.