Class Storage#copyFile
storage
- Defined in: storage.js
| Constructor Attributes | Constructor Name and Description |
|---|---|
|
Storage#copyFile(successCallback, errorCallback, options)
Copies file. |
Class Detail
Storage#copyFile(successCallback, errorCallback, options)
Copies file. File can be copied from internal, external memory, or remote site to internal, external memory, or a remote FTP site.
function copyFile() {
var successCb = function (){
console.log("Copying File done.");
};
var failureCb = function(cbObject){
var errorCode = cbObject.errorCode;
var errorText = cbObject.errorText;
console.log( " Error Code [" + errorCode + "]: " + errorText);
};
// Copy local file in internal memory to another location in internal memory.
var options_local_to_local = {
source: 'file://internal/copy_me.txt',
destination : 'file://internal/copy/to/here.txt'
};
var storage = new Storage();
storage.copyFile(successCb, failureCb, options_local_to_local);
// Copy remote file to internal memory.
// Then set the file as he source for an image tag.
var options_remote_to_local = {
source : 'http://remote.file.site/copy_me.txt',
destination : 'file://internal/copy/to/here.txt'
};
storage.copyFile(successCb, failureCb, options_remote_to_local);
// Copy file from USB memory at port 1 to internal memory.
var options_usb_to_local = {
source : 'file://usb:1/from/copy_me.txt',
destination : 'file://internal/copy/to/here.txt'
};
storage.copyFile(
function() { // Success Call back. Set the copied file as image source.
var imgElement = document.getElementById('myImage');
imgElement.src = 'http://127.0.0.1:9080/copy/to/here.jpg';
},
failureCb, options_usb_to_local);
// download remote file and copy to USB storage at port 1.
// Then set the file as he source for an image tag.
var options_remote_to_usb = {
source : 'http://remote.file.site/copy_me.jpg',
destination : 'file://usb:1/copy/to/here.jpg'
};
storage.copyFile(
function() { // Success Call back. Set the copied file as image source.
var imgElement = document.getElementById('myImage');
imgElement.src = 'http://127.0.0.1:9080/external/usb/1/copy/to/here.jpg';
},
failureCb, options_remote_to_usb);
// Copy file from redirected server.
var options_redirect = {
source : 'http://remote.site.that.will.redirect/copy_me.txt',
destination : 'file://usb:1/copy/to/here.txt',
maxRedirection: 5
};
storage.copyFile(successCb, failureCb, options_redirect);
// Copy file from ftp server.
var options_ftp = {
source : 'ftp://user:password@remote.ftp.site/copy_me.txt',
destination : 'file://internal/copy/to/here.txt',
};
storage.copyFile(successCb, failureCb, options_ftp);
// Copy internal file to ftp server.
var options_ftp2 = {
source : 'file://internal/send/me/away.txt',
destination : 'ftp://user:password@remote.ftp.site/sent.txt',
};
storage.copyFile(successCb, failureCb, options_ftp2);
}
- Parameters:
- {Function} successCallback
- success callback function.
- {Function} errorCallback
- failure callback function.
- {Object} options
Property Type Description Required source Storage.SCAP_URI URI to the source file required destination Storage.SCAP_URI URI to the destination file. required ftpOption Object FTP/SFTP options. Additional options for FTP setting. optional ftpOption.secureOptions Object secure FTP options optional ftpOption.secureOptions.privateKey String Private key for either key-based or hostbased user authentication (OpenSSH format) optional ftpOption.secureOptions.passphrase String For an encrypted private key, this is the passphrase used to decrypt it optional ftpOption.connTimeout Number How long (in milliseconds) to wait for the control connection to be established (default : 10000 ms) optional ftpOption.pasvTimeout Number How long (in milliseconds) to wait for a PASV data connection to be established (default : 10000 ms) optional ftpOption.keepalive Number How often (in milliseconds) to send a 'dummy'(NOOP) command to keep the connection alive (default : 10000 ms) optional httpOption Object HTTP/HTTPS file copy options optional httpOption.maxRedirection Number Maximum number of allowed redirections. Default value is 0, which means no redirection is allowed.Request will be redirected if the response code was 301, 302,303, or 307 and a valid location was found in the response header. This option is ignored if the source file is not a remote file. Maximum number of redirection is 5. optional httpOption.headers Object The [name : value] pairs that will be included in the HTTP request header, for remote file request. This header data will be cascaded during redirection. Maximum size of header data that can be contained is 1KB. optional httpOption.timeout Number Milliseconds before the underlying TCP connection times out. 0 is for no time out. Default value is 0. Note that if there is a server side timeout, copy file can timeout before the timeout value set by this option. optional
- Since:
- 1.0, 1.1 access to local file from remote application, 1.2 options.maxRedirection, 1.3 options.ftpOption, 1.3 options.maxRedirection moves to options.httpOption.maxRedirection, 1.3 options.httpOption.headers, 1.3 options.httpOption.timeout
- Returns:
After the method is successfully executed, successCallback is called without any parameter. If an error occurs, errorCallback is called with errorCode and errorText. To see how error codes are defined, check Error.ERROR_CODE