2016-04-20 12 views
0

ログアウト後に特定のユーザーがダウンロードしたキャッシュされた画像を削除したいモバイルアプリがあります。ユーザー1がログインし、ログインしている画像が少なく、ログインしている画像がほとんどありません。ユーザー2は他のユーザーのダウンロードした画像を見るべきではありません。cacheDirectory cache cordova file system ionicを削除する

 downloadFile : function(downloadLink, downloadFileName, downloadFileMimeType) { 
            $ionicLoading.show({ 
             template: '<ion-spinner></ion-spinner>' 
            }); 
            var accessToken = $window.localStorage.getItem(SYSTEM.AUTH_TOKEN); 
            var options = { 
             headers : { 
              'Authorization' : 'Bearer ' + accessToken 
             } 
            }; 

            var ext; 
            if (downloadFileMimeType == 'application/pdf') { 
             ext = '.pdf'; 
            } else { 
             ext = '.jpg'; 
            } 
            var localPath; 
            if(ionic.Platform.isAndroid()){ 
             localPath = cordova.file.externalCacheDirectory; 
            }else{ 
             localPath = cordova.file.cacheDirectory; 
            } 
            localPath = localPath + downloadFileName.trim().replace(/\s+/g, '-') + ext; 


            var ft = new FileTransfer(); 
            ft.download(downloadLink, localPath, function(entry) { 
             $ionicLoading.hide(); 
             console.log("Downloading report on path - " + entry.toURL()); 
             cordova.plugins.fileOpener2.open(entry.toURL(), downloadFileMimeType, { 
              error : function(e) { 
               console.log('Error status: ' + e.status + ' - Error message: ' + e.message); 
              }, 
              success : function(fileEntry) { 
               console.log('File opened successfully'); 
              } 

             }); 
            }, function fail(error) { 
             $ionicLoading.hide(); 
             console.log("Error while downloading report with error code - " + error.code); 
            }, true, options); 
           } 

答えて

0

あなたは、デバイスにユーザー固有のフォルダの下に特定のユーザーがダウンロードしたファイルを保存したときに他のユーザーがログインすると同じを削除することができます。そうでないあなたがファイルを保存しながら、ユーザーに固有の命名規則一部のファイルを追跡することができますフォルダや他のユーザーがログインするそれらのファイルに特定のユーザーに固有の削除、次のようにコルドバファイルプラグインを使用してディレクトリの削除とその内容について
サンプルスニペットは、次のとおりです。

function clearDirectory() { 
    if (ionic.Platform.isAndroid()) { 
     window.resolveLocalFileSystemURL(cordova.file.externalRootDirectory, onFileSystemDirSuccess, fail); 
    } else { 
     window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFileSystemDirSuccess, fail); 
    } 

function onFileSystemDirSuccess(fileSystem) { 
    var entry = ""; 
    if (ionic.Platform.isAndroid()) { 
     entry = fileSystem; 
    } else { 
     entry = fileSystem.root; 
    } 
    entry.getDirectory("DIRECTORY_TO_DELETE", { 
      create: true, 
      exclusive: false 
     }, 
     function(entry) { 
      entry.removeRecursively(function() { 
       console.log("Remove Recursively Succeeded"); 
      }, fail); 
     }, getDirFail); 
} 

function getDirFail(error) { 
    navigator.notification.alert("Error"); 
}; 

function fail(error) { 
    navigator.notification.alert("Error"); 
}; 

}

+0

たくさんウル再してくれてありがとうスポンサー。 –

+0

@AmitAnandそれが助けてくれてうれしい。ハッピーコーディング – Gandhi

関連する問題