Download images and save locally on iPhone Phonegap app

后端 未结 4 1727
梦如初夏
梦如初夏 2020-12-05 06:12

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 o

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-05 06:51

    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=="
                }
            }
        );
    

提交回复
热议问题