2016-04-02 16 views
3

コードオフプラグインファイル転送を使用しようとしていますhttp://ngcordova.com/docs/plugins/fileTransfer/なぜcordova.file.documentsDirectoryはnullですか?

ダウンロード場所を指定するコード例は次のとおりです。

var targetPath = cordova.file.documentsDirectory + "testImage.png"; 

ただし、このプロパティは存在しません。私はconsole.log(JSON.stringify(cordova.file))を記録しており、次の出力(フォーマット済み)を取得します。

{ 
    "applicationDirectory": "file:///android_asset/", 
    "applicationStorageDirectory": "file:///data/data/com.ionicframework.mobile379071/", 
    "dataDirectory": "file:///data/data/com.ionicframework.mobile379071/files/", 
    "cacheDirectory": "file:///data/data/com.ionicframework.mobile379071/cache/", 
    "externalApplicationStorageDirectory": "file:///storage/emulated/0/Android/data/com.ionicframework.mobile379071/", 
    "externalDataDirectory": "file:///storage/emulated/0/Android/data/com.ionicframework.mobile379071/files/", 
    "externalCacheDirectory": "file:///storage/emulated/0/Android/data/com.ionicframework.mobile379071/cache/", 
    "externalRootDirectory": "file:///storage/emulated/0/", 
    "tempDirectory": null, 
    "syncedDataDirectory": null, 
    "documentsDirectory": null, 
    "sharedDirectory": null 
} 

さらに、私はここhttps://cordova.apache.org/docs/en/dev/cordova-plugin-file/からいくつかのヒントに続き、次のように変更して、私のconfig.xmlを変更しました。

<preference name="AndroidPersistentFileLocation" value="Internal" /> 
<preference name="iosPersistentFileLocation" value="Library" /> 
<preference name="iosExtraFilesystems" value="library,library-nosync,documents,documents-nosync,cache,bundle,root" /> 
<preference name="AndroidExtraFilesystems" value="files,files-external,documents,sdcard,cache,cache-external,root" /> 

このコードは、エミュレータやブラウザでは実行されていませんが、実際のアンドロイドデバイスです。このプロパティがnullである理由に関するアイデア?

ファイルをダウンロードしようとすると、エラーが発生します。私のコードは次のようになります。

$cordovaFileTransfer.download(url, path, {}, true) 
    .then(function(result) { 
     console.log(JSON.stringify(result)); 
    }, function(err) { 
     console.log(JSON.stringify(err)); 
    }, function(progress) { 
     console.log(JSON.stringify(progress)); 
    }); 

これはエラーです(フォーマット済み)。

{ 
    "code": 1, 
    "source": "http://192.168.0.169/api/user/file/e95cdcfd541746b3b0721c992d756137", 
    "target": "IMG_20160224_030826.jpg", 
    "http_status": 200, 
    "body": null, 
    "exception": "/IMG_20160224_030826.jpg: open failed: EROFS (Read-only file system)" 
} 

私が間違っていることについてのアイデアはありますか? documentsDirectoryがヌルの場合はどちらを使用しますか?cordova.file.*

答えて

12

私がcordovaファイルのプラグインをチェックする限り、cordova.file.documentsDirectoryはAndroidでは無効です。

これはgithubのに公式ドキュメントをプラグインヴァファイルに記載された説明です:

"cordova.file.documentsDirectory - Files private to the app, but that are meaningful to other application (e.g. Office files). Note that for OSX this is the user's ~/Documents directory. (iOS, OSX)"

は、Android用cordova.file.externalDataDirectoryまたはcordova.file.externalRootDirectoryを試してみてください。希望します。

+0

ありがとうございます。それは本当に私の時間を節約しました。 –

+0

@AkashSaxena喜んで助けました – Gandhi

+0

問題の解決にお手伝いできますか? URLから画像をダウンロード中にこのエラーが発生します:FileTransferError {code:1、}このメソッドを使用しています$ cordovaFileTransfer.download(url、targetPath、options、trustHosts) –

関連する問題