下载图像和本地保存在iPhone Phonegap应用程序 [英] Download images and save locally on iPhone Phonegap app

查看:129
本文介绍了下载图像和本地保存在iPhone Phonegap应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经设法成功保存网页(x / html),但我也想保存其中包含的图像和mp4视频,以便在离线模式下进一步可视化。

I've already managed to save a web page (x/html) successfully, but I'd also like to save the images and mp4 videos that are contained in it, for further visualization in offline mode.

我可以访问iOS文件系统,所以我通过AJAX请求获取代码保存html,然后将其保存到一个文件。

I've got access to the iOS filesystem, so I save the html by obtaining the code through an AJAX request, and later saving it to a file.

我真的不知道如何用视频图片做同样的事情。我有一个服务器,我可以从我的应用程序发送查询,所以它只显示我需要下载的内容,以及最佳的标题,以防万一有必要。我只是不知道如何从客户端( Javascript )下载。

I don't really know how to do the same with video and images. I have a server to which I can send queries from my app, so it shows exclusively the content I need to download, with the optimal headers in case its necessary. I just don't know how to "download" it from the client side (Javascript).

感谢您提供任何帮助。 / p>

Thanks in advance for any help.

推荐答案

您可以使用 FileTransfer 对象将远程映像下载到本地文件。

You can use a FileTransfer object to download a remote image to a local file.

这是最新的官方示例代码片段:

This is the latest official sample snippet:

    // !! Assumes filePath is a valid path on the device

    var fileTransfer = new FileTransfer();
    var uri = encodeURI("http://some.server.com/download.php");

    fileTransfer.download(
        uri,
        filePath,
        function(entry) {
            console.log("download complete: " + entry.fullPath);
        },
        function(error) {
            console.log("download error source " + error.source);
            console.log("download error target " + error.target);
            console.log("upload error code" + error.code);
        },
        false,
        {
            headers: {
                "Authorization": "Basic dGVzdHVzZXJuYW1lOnRlc3RwYXNzd29yZA=="
            }
        }
    );

这篇关于下载图像和本地保存在iPhone Phonegap应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆