2016-10-05 4 views
0

필자는 대부분의 코드바 파일 관련 플러그인을 사용해 보았고 마지막으로이 코드를 사용했습니다. 그것은 성공 메시지를주고 있지만 갤러리에 나타나지 않았습니다. 아무도 이것으로 도와 줄 수 있니?ionic app에서 서버의 이미지를 장치 내부 메모리에 저장하는 방법은 무엇입니까?

$scope.download = function download(name, contentType, fileLInk) { 
ionic.Platform.ready(function() { 
    var url = apiServiceBaseUri + fileLInk; 
    var targetPath = cordova.file.dataDirectory + 'myapp/' + name; 
    var trustHosts = false; 
    var options = { 
    headers: { 
     'Authorization': tokenType + ' ' + accessToken 
    } 
    }; 

    $cordovaFileTransfer.download(url, targetPath, options, trustHosts) 
    .then(function(result) { 
     var alertPopup = $ionicPopup.alert({ 
     title: 'File has been downloaded', 
     }); 
     $ionicListDelegate.closeOptionButtons(); 
    }, function(error) { 
     $ionicListDelegate.closeOptionButtons(); 
     if (error.http_status == 401) { 
     $ionicPopup.alert({ 
      title: 'Oops, Session is expired!', 
      template: 'Looks like your session is expired or you logged in from someother device.' 
     }); 
     $ionicHistory.clearCache().then(function() { 
      $state.go('start.login'); 
     }); 
     } 
     var alertPopup = $ionicPopup.alert({ 
     title: 'Sorry, something went wrong during the request!', 
     template: error.data.errors[0].message 
     }); 
    }); 
}); 
}; 

답변

0

당신은

$cordovaFileTransfer.download(url, targetPath, options, trustHosts) 
    .then(function(result) { 
    refreshMedia.refresh(targetPath); 
    //some other things 

내 작업 코드

을 파일 전송

cordova plugin add cordova-plugin-refresh-gallery 

후이 플러그인을 사용하여 파일 전송의 성공의 callbeck에서이 기능을 사용한다

$cordovaFileTransfer.download(url, targetPath, {}, true).then(function (result) { 
       refreshMedia.refresh(targetPath); 
       $scope.fullViewImageDownloadSpiner = false; 
       tostService.notify('Image Downloaded', 'top'); 
      }, function (error) { 
       $scope.fullViewImageDownloadSpiner = false; 
       tostService.notify('Try Again', 'top'); 
      }, function (progress) { 
       // PROGRESS HANDLING GOES HERE 
       // $timeout(function() { 
       //  $scope.downloadProgress = (progress.loaded/progress.total) * 100; 
       // }) 
      }); 

var filename = url.split("/").pop(); 
var targetPath = cordova.file.externalRootDirectory + '/Download/' + filename; 

이 플러그인은 당신의 안드로이드 장치에 이미지를 저장 gallery.When 이미지를 업데이트하고 이미지 이미지가

희망을 작동 갤러리 .This 플러그인에 표시되지 않는 대상 경로를 설정 이게 당신의 문제를 해결 .. 고마워 :)

+0

답장을 보내 주셔서 감사합니다 @ ujjwal kaushik. 실제로, 나는 그것을 또한 시도했다. 그러나 어떤 운도. –

+0

그것은 나를 위해 일했습니다. 너를 위해 일하지 않니? –

+0

그렇지 않습니다. 실제로, 나는 그 플러그인을 설치하고이 라인을 성공 호출에 추가했다. $ cordovaFileTransfer.download (URL,있는 TargetPath, 옵션, trustHosts) 그 때는 (기능 (결과) { refreshMedia.refresh (있는 TargetPath) }, 기능 (오류) { // 오류가 간다} }); –

관련 문제