Overview


The file transfer API can be leveraged for the FileTransfer object to either download a file from a remote server by using the download method or upload a file from the local storage using the upload method. Any file transfer operation that has started can also be canceled at any time before it has finished using the cancel method on the FileTransferTask object.

The download method allows a user to specify the following parameters:

The upload method allows a user to specify the following parameters:

Note

File transfer processes are active only while the application is running. Transferring a file of the same name to the same location results in the existing file being overwritten.

Module

The classes/methods for this API belong to the File Transfer product module.

Example

The following example illustrates the use of the file transfer API.

var options = {
  credentials: "admin:secret",
  headers: {
  	"sample-header": "sample-value",
  	"sample-multi-header": ["sample-multi-value1","sample-multi-value2"]
  },
  params: {
  	"paramA": "valueA",
  	"paramB": "valueB"
  }
}

var callback = {
    onSuccess: function (entry) {
        console.log("onSuccess " + JSON.stringify(entry));
            entry.file(function (file) {
                var reader = new FileReader();
                reader.onload = function () {
                    console.log("content = " + reader.result);
                };
                try {
                    reader.readAsText(file);
                } catch (e) {
                    console.log("reader.readAsText error: " + 
                                      JSON.stringify(e));
                }
            }, function (err) {
                console.log("file error: " + JSON.stringify(err));
            });
    },
    onProgress: function (progress) {
        console.log("onProgress " + progress);
    },
    onCancel: function () {
        console.log("onCancel");
    },
    onFailure: function (data) {
        console.log("onFailure " + JSON.stringify(data));
    }
};

requestFileSystem(window.PERSISTENT, 60 * 1024 * 1024, function (fs) {
    fs.root.getFile("file.txt", {create: true}, function (entry) {
        launchbox.FileTransfer.download("http://example.com/file.txt", 
                                        entry.toURL(), 
                                        options, 
                                        callback);
    }, function (err) {
        console.log("getFile error: " + JSON.stringify(err));
    });
}, function (err) {
    console.log("requestFileSystem error: " + JSON.stringify(err));
});

Related topics

FileTransfer
FileTransferTask
Legal notice | Copyright © 2018 and Confidential to Pegasystems Inc. All rights reserved
PDN | Feedback
Advanced...