Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/205.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在移动设备(Android、iPhone、Windows)中下载base-64源图像并保存到设备手机内存中_Android_Ios_Asp.net_Download_Telerik Appbuilder - Fatal编程技术网

如何在移动设备(Android、iPhone、Windows)中下载base-64源图像并保存到设备手机内存中

如何在移动设备(Android、iPhone、Windows)中下载base-64源图像并保存到设备手机内存中,android,ios,asp.net,download,telerik-appbuilder,Android,Ios,Asp.net,Download,Telerik Appbuilder,我使用telerik app builder创建了一个示例应用程序。我创建了一个简单视图和一个js文件,在视图中渲染一个图像,并将其转换为base-64。我需要下载此图像并使用javascript将其保存到设备内部存储 我使用了javascript的download.js插件,但下载功能不起作用。请给出建议 我的代码如下: 我找到了自己问题的答案 您可以使用cordova filetransfer在移动设备中下载图像 function download() { var filepath

我使用telerik app builder创建了一个示例应用程序。我创建了一个简单视图和一个js文件,在视图中渲染一个图像,并将其转换为base-64。我需要下载此图像并使用javascript将其保存到设备内部存储

我使用了javascript的download.js插件,但下载功能不起作用。请给出建议

我的代码如下:
我找到了自己问题的答案

您可以使用cordova filetransfer在移动设备中下载图像

function download()
{
    var filepath = encodeURI("http://www.telerik.com/sfimages/default-source/logos/app_builder.png"),
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fileSystem) {
                fileSystem.root.getFile("sample.jpg", { create: true, exclusive: false }, function (fileEntry) {

                    // get the full path to the newly created file on the device
                    var localPath = fileEntry.fullPath;

                    // massage the path for android devices (not tested)
                    if (device.platform === "Android" && localPath.indexOf("file://") === 0) {
                        localPath = localPath.substring(7);
                    }

                    // download the remote file and save it
                    var remoteFile = filepath;
                    //loadingOverlay.displayLoading("Image will be save on your device.");

                    var fileTransfer = new FileTransfer();
                    fileTransfer.download(remoteFile, localPath, function (newFileEntry) {
                        // successful download, continue to the next image
                        var dwnldImagePath = newFileEntry.fullPath;
                        console.log('successful download');

                    },
                    function (error) { // error callback for #download
                        console.log('Error with #download method.', error);

                    });
                });
                function(error) { // error callback for #getFile
                    console.log('Error with #getFile method.', error);
                });

            })
}

我找到了自己问题的答案

您可以使用cordova filetransfer在移动设备中下载图像

function download()
{
    var filepath = encodeURI("http://www.telerik.com/sfimages/default-source/logos/app_builder.png"),
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fileSystem) {
                fileSystem.root.getFile("sample.jpg", { create: true, exclusive: false }, function (fileEntry) {

                    // get the full path to the newly created file on the device
                    var localPath = fileEntry.fullPath;

                    // massage the path for android devices (not tested)
                    if (device.platform === "Android" && localPath.indexOf("file://") === 0) {
                        localPath = localPath.substring(7);
                    }

                    // download the remote file and save it
                    var remoteFile = filepath;
                    //loadingOverlay.displayLoading("Image will be save on your device.");

                    var fileTransfer = new FileTransfer();
                    fileTransfer.download(remoteFile, localPath, function (newFileEntry) {
                        // successful download, continue to the next image
                        var dwnldImagePath = newFileEntry.fullPath;
                        console.log('successful download');

                    },
                    function (error) { // error callback for #download
                        console.log('Error with #download method.', error);

                    });
                });
                function(error) { // error callback for #getFile
                    console.log('Error with #getFile method.', error);
                });

            })
}