2016-12-21 2 views
0

からVCFファイルをアップロードし、私は今からそのVCFファイルやvCardの読み込み方に助けを必要と私の以前のquestion(編集されている1)読み取りは、サーバ

からの助けを得る上で、サーバー上で正常にVCFファイルをアップロードしています私のphonegapアプリに連絡先と連絡先の名前として表示します。 cordova-plugin-file-transfer

を使用

プラグインは、誰もがこの上で役立つことはできますか?

答えて

2

プラグインコードバープラグインファイル転送https://github.com/apache/cordova-plugin-file-transferを使用すると、サーバーからファイルをダウンロードできます。

vcfファイルを読むには、https://github.com/nilclass/vcardjs JavaScriptベースのライブラリが必要です。 .jsファイルを直接使用することができます。

以下の例に従うことができます。

window.requestFileSystem(window.TEMPORARY, 1 * 1024 * 1024, function (fs) { 

     console.log('file system open: ' + fs.name); 
     var fileName = "temp.vcf"; 
     var dirEntry = fs.root; 
     dirEntry.getFile(fileName, { create: true, exclusive: false }, function (fileEntry) { 

      download(fileEntry,"server-path-to-file.vcf"); 

     }, onErrorCreateFile); 

    }, onErrorLoadFs); 




function download(fileEntry, uri) { 

    var fileTransfer = new FileTransfer(); 
    var fileURL = fileEntry.toURL(); 

    fileTransfer.download(
     uri, 
     fileURL, 
     function (entry) { 
      console.log("Successful download..."); 
      console.log("download complete: " + entry.toURL()); 
      readFile(entry); 
     }, 
     function (error) { 
      console.log("download error source " + error.source); 
      console.log("download error target " + error.target); 
      console.log("upload error code" + error.code); 
     }, 
     null, // or, pass false 
     { 
      //headers: { 
      // "Authorization": "Basic dGVzdHVzZXJuYW1lOnRlc3RwYXNzd29yZA==" 
      //} 
     } 
    ); 
} 


function readFile(fileEntry) { 
    fileEntry.file(function (file) { 

     var reader = new FileReader(); 

     reader.onloadend = function() { 

      console.log("Successful file read: " + reader.result); 
      reader.parseVCard(reader.result); 

     }; 

     reader.readAsText(file); 

    }, onErrorReadFile); 
} 

function parseVCard(vCarddata){ 
VCF.parse(vCarddata, function(vcard) { 
    // this function is called with a VCard instance. 
    // If the input contains more than one vCard, it is called multiple times. 
    console.log("Formatted name", vcard.fn); 
    console.log("Names", JSON.stringify(vcard.n)); 
}); 
//Fore more help:https://github.com/nilclass/vcardjs 
} 
+0

........このソリューションは罰金:-) – Bunny

+0

..このソリューションを試してみて、あなたが知っているだろう:) – Bunny

+0

は素晴らしい作品 –

関連する問題