Webview应用程序无法将下载的文件保存在设备文件系统中

时间:2016-05-17 03:52:55

标签: javascript

我正在编写一个WebView android应用程序来下载文件并将其保存到我的移动设备中。该文件可以下载但无法保存到我的设备中。发生了什么,我该如何解决?

        function downloadContentVersion(nodeId, version) {
        var url = '';
        self.getDownloadUrl(nodeId, version ? version.version : null).then(function (response) {
            url = response.data.data.contentUrl;
           alert('hi 1');

            return $http({
                'method': 'GET',
                'responseType': 'arraybuffer',
                'url':  config.basePath + url.substring(url.indexOf('/downloadURL'))
            });
        }).then(function (response) {
            if (/iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream) {
                window.open( config.basePath + url, '_blank');
                alert('hey' + window.open );
            } else {
                var blob = new Blob([response.data], {
                    type: response.headers("Content-Type")
                });
                saveAs(blob, version ? version.filename : extractFileName(response));
                alert('hello' + blob);
            }
        });
    }

    function extractFileName(response) {
        var url = response.config.url;
         alert('oook' + url );
        return url.substring(url.lastIndexOf('/') + 1);

    }

0 个答案:

没有答案