Class: GDFileTransfer

GDFileTransfer()

FileTransfer downloads/uploads a file from/to a remote server.

Methods

download(source, target, successCallback, errorCallback)

Downloads a file form a given URL and saves it to the specified directory.
Parameters:
Name Type Description
source String URL of the server to receive the file
target String Full path of the file on the device
successCallback function Callback to be invoked when upload has completed
errorCallback function Callback to be invoked upon error
Source:
Example
var fileTransfer = new FileTransfer(),
    url = "http://www.textfiles.com/programming/24hrs.txt",
    filePath = "/file.txt",
    options = {create: true, exclusive: false};
options.fileKey = "file";
options.fileName = "data.json";
options.mimeType = "text/json";

requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fileSystem) {
    fileSystem.root.getFile(filePath, fileOptions, function (file) {
        fileTransfer.download(url, file.fullPath, function (downloadedEntry) {
            downloadedEntry.file(function (downloadedFile) {
                console.log(downloadedFile);
            });
        }, null);
    }, null);
});

upload(filePath, server, successCallback, errorCallback, options, trustAllHosts)

Given an absolute file path, uploads a file on the device to a remote server using a multipart HTTP request.
Parameters:
Name Type Description
filePath String Full path of the file on the device
server String URL of the server to receive the file
successCallback function Callback to be invoked when upload has completed
errorCallback function Callback to be invoked upon error
options FileUploadOptions Optional parameters such as file name and mimetype
trustAllHosts Boolean Optional trust all hosts (e.g. for self-signed certs), defaults to false
Source:
Example
var ft = new FileTransfer(),
    options = new FileUploadOptions(),
    filePath = "file.txt",
    fileOptions = {create: true, exclusive: false},
    uploadUrl = "http://httpbin.org/post";
options.fileKey = "file";
options.fileName = "data.json";
options.mimeType = "text/json";

requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fileSystem) {
    fileSystem.root.getFile(filePath, fileOptions, function (file) {
        file.createWriter(function (writer) {
            writer.onwriteend = function() {
                ft.upload(file.fullPath, uploadUrl, function (response) {
                    consol.log(response);
                }, null, options, true);
                ft.onprogress = function(progress) {
                    console.log(progress)
                };
            }
            writer.write('File writer wrote this text');
        }, null);
    }, null);
});