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

查看:27
本文介绍了下载图像并本地保存在 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).

在此先感谢您的帮助.

推荐答案

您可以使用 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天全站免登陆