Reputation: 820
i am trying to create & read both for vcard, after googleng for a while not getting a proper example of it, is there any vcard creator/ reader to start ,
i am trying this https://www.npmjs.org/package/vcard
my code to it
app.get('/',function(req,res){
//https://github.com/Fusselwurm/vcard-js/commit/dafd17ffd226c6170849be82e9c5dae94e23b8f0
card.readFile("./public/sample.vcf", function(err, json1) {
if(err){
console.log("vcard err "+err);
res.json(util.inspect(json1));
}
else
{
console.log("vcard json "+json1);
console.log("vcard json "+util.inspect(json1));
res.json(util.inspect(json1));
}
});
});
sample.vcf file
BEGIN:VCARD VERSION:3.0 N:Gump;Forrest;;Mr. FN:Forrest Gump ORG:Bubba Gump Shrimp Co. TITLE:Shrimp Man TEL;TYPE=HOME,VOICE:(111) 555-1212 PHOTO;VALUE=URL;TYPE=GIF:http://www.example.com/dir_photos/my_photo.gif TEL;TYPE=WORK,VOICE:(111) 555-12121 ADR;TYPE=WORK:;;100 Waters Edge;Baytown;LA;30314;United States of America LABEL;TYPE=WORK:100 Waters Edge\nBaytown, LA 30314\nUnited States of America ADR;TYPE=HOME:;;42 Plantation St.;Baytown;LA;30314;United States of America LABEL;TYPE=HOME:42 Plantation St.\nBaytown, LA 30314\nUnited States of America EMAIL;TYPE=PREF,INTERNET:[email protected] REV:2008-04-24T19:52:43Z END:VCARD BEGIN:VCARD VERSION:3.0 N:Gump;Forrest;;Mr. FN:Forrest Gump ORG:Bubba Gump Shrimp Co. TITLE:Shrimp Man TEL;TYPE=HOME,VOICE:(111) 555-1212 PHOTO;VALUE=URL;TYPE=GIF:http://www.example.com/dir_photos/my_photo.gif TEL;TYPE=WORK,VOICE:(111) 555-12121 ADR;TYPE=WORK:;;100 Waters Edge;Baytown;LA;30314;United States of America LABEL;TYPE=WORK:100 Waters Edge\nBaytown, LA 30314\nUnited States of America ADR;TYPE=HOME:;;42 Plantation St.;Baytown;LA;30314;United States of America LABEL;TYPE=HOME:42 Plantation St.\nBaytown, LA 30314\nUnited States of America EMAIL;TYPE=PREF,INTERNET:[email protected] REV:2008-04-24T19:52:43Z END:VCARD
logcat output: it works for only 1 vcard data in sample.vcf, but when it contains more data then it throughs error i.e Invalid vCard data: One or more required elements are missing (VERSION and FN)
Upvotes: 2
Views: 5588
Reputation: 13587
I think there's a couple of issues here:
Have a look at vcardparser
library instead.
var vcardparser = require('vcardparser');
vcardparser.parseFile("./sample.vcf", function(err, json) {
if(err)
return console.log(err);
console.log(json);
});
Here's a sample vcard:
BEGIN:VCARD
VERSION:4.0
N:Gump;Forrest;;;
FN:Forrest Gump
ORG:Bubba Gump Shrimp Co.
TITLE:Shrimp Man
PHOTO;MEDIATYPE=image/gif:http://www.example.com/dir_photos/my_photo.gif
TEL;TYPE=work,voice;VALUE=uri:tel:+1-111-555-1212
TEL;TYPE=home,voice;VALUE=uri:tel:+1-404-555-1212
ADR;TYPE=work;LABEL="100 Waters Edge\nBaytown, LA 30314\nUnited States of America"
:;;100 Waters Edge;Baytown;LA;30314;United States of America
ADR;TYPE=home;LABEL="42 Plantation St.\nBaytown, LA 30314\nUnited States of America"
:;;42 Plantation St.;Baytown;LA;30314;United States of America
EMAIL:[email protected]
REV:20080424T195243Z
END:VCARD
And the output from vcardparser
{ begin: 'VCARD',
version: '4.0',
n:
{ last: 'Gump',
first: 'Forrest',
middle: '',
prefix: '',
suffix: '' },
fn: 'Forrest Gump',
org: { name: 'Bubba Gump Shrimp Co.', dept: undefined },
title: 'Shrimp Man',
photo:
{ type: [],
value: 'http://www.example.com/dir_photos/my_photo.gif' },
tel:
[ { type: [Object], value: 'tel:+1-111-555-1212' },
{ type: [Object],
value: 'tel:+1-404-555-1212ADR;TYPE=work;LABEL="100 Waters Edge\\nBaytown, LA 30314\\nUnited States of America"' } ],
' ': ';;100 Waters Edge;Baytown;LA;30314;United States of AmericaADR;TYPE=home;LABEL="42 Plantation St.\\nBaytown, LA 30314\\nUnited States of America"',
' ': ';;42 Plantation St.;Baytown;LA;30314;United States of America',
email: [ { type: [], value: '[email protected]' } ],
rev: '20080424T195243Z',
end: 'VCARD' }
Upvotes: 5