2012-04-06 9 views
3

私はファイル(pdf、doc、txt)をダウンロードする必要があるphonegapアプリケーションを書いています。
私はphonegap 1.5.0すなわちcordova 1.5.0.jsファイルを使用しています。blackgreenとwindows mango用のphonegap 1.5(Cordova)を使ってファイルをダウンロードするには?

私は
http://docs.phonegap.com/en/1.5.0/phonegap_file_file.md.html#FileTransfer
でのPhoneGap APIのに見て、変数をFileTransferのダウンロード方法を使用しようとしています。

save: function (fileName, fileType, url) { 
    documentsaver.fileName = fileName; 
    documentsaver.fileType = fileType; 
    documentsaver.url = url; 
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, fsSuccess, fail); 

    function fail(event) { 
     jqmSimpleMessage('Error Code ' + event.target.error.code); 
    } 

    function fsSuccess(fileSystem) { 
     documentsaver.directoryEntry = fileSystem.root; 

     //Creating directory in which document should be saved if it does not exist 
     documentsaver.directoryEntry.getDirectory(documentsaver.directoryName, { create: true, exclusive: false }, dirSuccess, fail); 

     function dirSuccess(parent) { 
      console.log('Directory Created at '+parent.fullPath+' with name '+parent.name); 
      //Moving directoryEntry reference to newly created directory 
      documentsaver.directoryEntry = parent; 

      //Creating file which will be written 
      var completeFileName = documentsaver.fileName + '.' + documentsaver.fileType; 
      console.log('completeFileName === >' + completeFileName); 
      var filePath = documentsaver.directoryEntry.fullPath + '/' + completeFileName; 
      console.log('filePath === >' + filePath); 

      var fileTransfer = new FileTransfer(); 
      fileTransfer.download(
        url, 
        filePath, 
        function(entry) { 
         console.log("download complete: " + entry.fullPath); 
        }, 
        function(error) { 
         console.log("download error source " + error.source); 
         console.log("download error target " + error.target); 
         console.log("upload error code" + error.code); 
        } 
       ); 
     } 



ファイル名::私は保存していたファイルの名前以下は、私が使用していたコードです。
fileType: fileTypeつまりpdfまたはdocまたはpng。
url:実際のリソースへのURL。

ログイン:私は窓のエミュレータ上でそれを実行すると、コンソールログが続き

「これがDIRである」
スレッド「」(0xf0a01c6)はコード0(0x0の)で終了しました。
ログ: "filePath ===>/JarusDocuments/Personal Auto Application.pdf"
スレッド '(0xff001f6)がコード0(0x0)で終了しました。
ログ:「成功コールバックでエラーが発生しました::FILE11は=オブジェクトがプロパティまたはメソッドをサポートしていません 『ダウンロード』」
スレッド「」(0xe3201b6)で終了しました
ログ「名前JarusDocumentsとJarusDocuments /で作成したディレクトリ」コード0(0x0)。
スレッド ''(0xf18014e)がコード0(0x0)で終了しました。
ログ: "completeFileName ===" Personal Auto Application.pdf "
スレッド"(0xf1c01de)がコード0(0x0)で終了しました。

FileTransferはダウンロード方法をサポートしていません。ログにはすでに、私が望むすべてのディレクトリを作成できることが記載されていますが。

答えて

1

PhoneGap 1.5 for WP7では、FileTransferオブジェクトはダウンロード可能ではありません(アップロードのみ)。しかし、1.6版はこれを行うことができると主張しています(あなたは、hereに関するphonegapのブログ記事で自分で読むことができます)

関連する問題