Return-Path: X-Original-To: apmail-cordova-commits-archive@www.apache.org Delivered-To: apmail-cordova-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id EE18EFA0E for ; Fri, 31 May 2013 17:58:28 +0000 (UTC) Received: (qmail 22727 invoked by uid 500); 31 May 2013 17:58:28 -0000 Delivered-To: apmail-cordova-commits-archive@cordova.apache.org Received: (qmail 22699 invoked by uid 500); 31 May 2013 17:58:28 -0000 Mailing-List: contact commits-help@cordova.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cordova.apache.org Delivered-To: mailing list commits@cordova.apache.org Received: (qmail 22677 invoked by uid 99); 31 May 2013 17:58:28 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 31 May 2013 17:58:28 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 12AD489ED83; Fri, 31 May 2013 17:58:27 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: steven@apache.org To: commits@cordova.apache.org Date: Fri, 31 May 2013 17:58:39 -0000 Message-Id: In-Reply-To: <8f63d0f76bdf4c9b91a683d7e5cb4c9a@git.apache.org> References: <8f63d0f76bdf4c9b91a683d7e5cb4c9a@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [13/23] updated version http://git-wip-us.apache.org/repos/asf/cordova-docs/blob/40331cf8/docs/en/2.8.0rc1/edge/cordova/events/events.searchbutton.md ---------------------------------------------------------------------- diff --git a/docs/en/2.8.0rc1/edge/cordova/events/events.searchbutton.md b/docs/en/2.8.0rc1/edge/cordova/events/events.searchbutton.md new file mode 100644 index 0000000..f571a4d --- /dev/null +++ b/docs/en/2.8.0rc1/edge/cordova/events/events.searchbutton.md @@ -0,0 +1,86 @@ +--- +license: Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--- + +searchbutton +=========== + +This is an event that fires when the user presses the search button on Android. + + document.addEventListener("searchbutton", yourCallbackFunction, false); + +Details +------- + +If you need to override the default search button behaviour on Android you can register an event listener for the 'searchbutton' event. + +Typically, you will want to attach an event listener with `document.addEventListener` once you receive the Cordova 'deviceready' event. + +Supported Platforms +------------------- + +- Android + +Quick Example +------------- + + document.addEventListener("searchbutton", onSearchKeyDown, false); + + function onSearchKeyDown() { + // Handle the search button + } + +Full Example +------------ + + + + + Cordova Search Button Example + + + + + + + http://git-wip-us.apache.org/repos/asf/cordova-docs/blob/40331cf8/docs/en/2.8.0rc1/edge/cordova/events/events.startcallbutton.md ---------------------------------------------------------------------- diff --git a/docs/en/2.8.0rc1/edge/cordova/events/events.startcallbutton.md b/docs/en/2.8.0rc1/edge/cordova/events/events.startcallbutton.md new file mode 100644 index 0000000..5f2c112 --- /dev/null +++ b/docs/en/2.8.0rc1/edge/cordova/events/events.startcallbutton.md @@ -0,0 +1,86 @@ +--- +license: Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--- + +startcallbutton +=========== + +This is an event that fires when the user presses the start call button. + + document.addEventListener("startcallbutton", yourCallbackFunction, false); + +Details +------- + +If you need to override the default start call behaviour you can register an event listener for the 'startcallbutton' event. + +Typically, you will want to attach an event listener with `document.addEventListener` once you receive the Cordova 'deviceready' event. + +Supported Platforms +------------------- + +- BlackBerry WebWorks (OS 5.0 and higher) + +Quick Example +------------- + + document.addEventListener("startcallbutton", onStartCallKeyDown, false); + + function onStartCallKeyDown() { + // Handle the start call button + } + +Full Example +------------ + + + + + Cordova Start Call Button Example + + + + + + + http://git-wip-us.apache.org/repos/asf/cordova-docs/blob/40331cf8/docs/en/2.8.0rc1/edge/cordova/events/events.volumedownbutton.md ---------------------------------------------------------------------- diff --git a/docs/en/2.8.0rc1/edge/cordova/events/events.volumedownbutton.md b/docs/en/2.8.0rc1/edge/cordova/events/events.volumedownbutton.md new file mode 100644 index 0000000..8f27ce2 --- /dev/null +++ b/docs/en/2.8.0rc1/edge/cordova/events/events.volumedownbutton.md @@ -0,0 +1,86 @@ +--- +license: Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--- + +volumedownbutton +=========== + +This is an event that fires when the user presses the volume down button. + + document.addEventListener("volumedownbutton", yourCallbackFunction, false); + +Details +------- + +If you need to override the default volume down behaviour you can register an event listener for the 'volumedownbutton' event. + +Typically, you will want to attach an event listener with `document.addEventListener` once you receive the Cordova 'deviceready' event. + +Supported Platforms +------------------- + +- BlackBerry WebWorks (OS 5.0 and higher) + +Quick Example +------------- + + document.addEventListener("volumedownbutton", onVolumeDownKeyDown, false); + + function onVolumeDownKeyDown() { + // Handle the volume down button + } + +Full Example +------------ + + + + + Cordova Volume Down Button Example + + + + + + + http://git-wip-us.apache.org/repos/asf/cordova-docs/blob/40331cf8/docs/en/2.8.0rc1/edge/cordova/events/events.volumeupbutton.md ---------------------------------------------------------------------- diff --git a/docs/en/2.8.0rc1/edge/cordova/events/events.volumeupbutton.md b/docs/en/2.8.0rc1/edge/cordova/events/events.volumeupbutton.md new file mode 100644 index 0000000..9fb38b1 --- /dev/null +++ b/docs/en/2.8.0rc1/edge/cordova/events/events.volumeupbutton.md @@ -0,0 +1,86 @@ +--- +license: Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--- + +volumeupbutton +=========== + +This is an event that fires when the user presses the volume up button. + + document.addEventListener("volumeupbutton", yourCallbackFunction, false); + +Details +------- + +If you need to override the default volume up behaviour you can register an event listener for the 'volumeupbutton' event. + +Typically, you will want to attach an event listener with `document.addEventListener` once you receive the Cordova 'deviceready' event. + +Supported Platforms +------------------- + +- BlackBerry WebWorks (OS 5.0 and higher) + +Quick Example +------------- + + document.addEventListener("volumeupbutton", onVolumeUpKeyDown, false); + + function onVolumeUpKeyDown() { + // Handle the volume up button + } + +Full Example +------------ + + + + + Cordova Volume Up Button Example + + + + + + + http://git-wip-us.apache.org/repos/asf/cordova-docs/blob/40331cf8/docs/en/2.8.0rc1/edge/cordova/file/directoryentry/directoryentry.md ---------------------------------------------------------------------- diff --git a/docs/en/2.8.0rc1/edge/cordova/file/directoryentry/directoryentry.md b/docs/en/2.8.0rc1/edge/cordova/file/directoryentry/directoryentry.md new file mode 100644 index 0000000..8b11012 --- /dev/null +++ b/docs/en/2.8.0rc1/edge/cordova/file/directoryentry/directoryentry.md @@ -0,0 +1,397 @@ +--- +license: Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--- + +DirectoryEntry +============== + +This object represents a directory on a file system. It is defined in the [W3C Directories and Systems](http://www.w3.org/TR/file-system-api/) specification. + +Properties +---------- + +- __isFile:__ Always false. _(boolean)_ +- __isDirectory:__ Always true. _(boolean)_ +- __name:__ The name of the DirectoryEntry, excluding the path leading to it. _(DOMString)_ +- __fullPath:__ The full absolute path from the root to the DirectoryEntry. _(DOMString)_ + +NOTE: The following attributes are defined by the W3C specification, but are __not supported__ by Cordova: + +- __filesystem:__ The file system on which the DirectoryEntry resides. _(FileSystem)_ + +Methods +------- + +The following methods can be invoked on a DirectoryEntry object: + +- __getMetadata__: Look up metadata about a directory. +- __setMetadata__: Set metadata on a directory. +- __moveTo__: Move a directory to a different location on the file system. +- __copyTo__: Copy a directory to a different location on the file system. +- __toURL__: Return a URL that can be used to locate a directory. +- __remove__: Delete a directory. The directory must be empty. +- __getParent__: Look up the parent directory. +- __createReader__: Create a new DirectoryReader that can read entries from a directory. +- __getDirectory__: Create or look up a directory. +- __getFile__: Create or look up a file. +- __removeRecursively__: Delete a directory and all of its contents. + + +Supported Platforms +------------------- + +- Android +- BlackBerry WebWorks (OS 5.0 and higher) +- iOS +- Windows Phone 7 and 8 +- Windows 8 + +getMetadata +----------- + +Look up metadata about a directory. + +__Parameters:__ + +- __successCallback__ - A callback that is called with a Metadata object. _(Function)_ +- __errorCallback__ - A callback that is called if an error occurs retrieving the Metadata. Invoked with a FileError object. _(Function)_ + + +__Quick Example__ + + function success(metadata) { + console.log("Last Modified: " + metadata.modificationTime); + } + + function fail(error) { + alert(error.code); + } + + // Request the metadata object for this entry + entry.getMetadata(success, fail); + +setMetadata +---------------- + +Set metadata on a directory. +**Only works on iOS currently** - this will set the extended attributes of a directory. + +__Parameters:__ + +- __successCallback__ - A callback that is called when the metadata was successfully set. _(Function)_ +- __errorCallback__ - A callback that is called when the metadata was not successfully set. _(Function)_ +- __metadataObject__ - An object that contains the metadata keys and values. _(Object)_ + + +__Quick Example__ + + function success() { + console.log("The metadata was successfully set."); + } + + function fail() { + alert("There was an error in setting the metadata"); + } + + // Set the metadata + entry.setMetadata(success, fail, { "com.apple.MobileBackup": 1}); +__iOS Quirk__ + +- only the **"com.apple.MobileBackup"** extended attribute is supported. Set the value to **1** to NOT enable the directory to be backed up by iCloud. Set the value to **0** to re-enable the directory to be backed up by iCloud. + +__Quick Example__ + + function setFolderMetadata(localFileSystem, subFolder, metadataKey, metadataValue) + { + var onSetMetadataWin = function() { + console.log("success setting metadata") + } + var onSetMetadataFail = function() { + console.log("error setting metadata") + } + + var onGetDirectoryWin = function(parent) { + var data = {}; + data[metadataKey] = metadataValue; + parent.setMetadata(onSetMetadataWin, onSetMetadataFail, data); + } + var onGetDirectoryFail = function() { + console.log("error getting dir") + } + + var onFSWin = function(fileSystem) { + fileSystem.root.getDirectory(subFolder, {create: true, exclusive: false}, onGetDirectoryWin, onGetDirectoryFail); + } + + var onFSFail = function(evt) { + console.log(evt.target.error.code); + } + + window.requestFileSystem(localFileSystem, 0, onFSWin, onFSFail); + } + + setFolderMetadata(LocalFileSystem.PERSISTENT, "Backups", "com.apple.MobileBackup", 1); + +moveTo +------ + +Move a directory to a different location on the file system. It is an error to attempt to: + +- move a directory inside itself or to any child at any depth; +- move a directory into its parent if a name different from its current one is not provided; +- move a directory to a path occupied by a file; +- move a directory to a path occupied by a directory which is not empty. + +In addition, an attempt to move a directory on top of an existing empty directory must attempt to delete and replace that directory. + +__Parameters:__ + +- __parent__ - The parent directory to which to move the directory. _(DirectoryEntry)_ +- __newName__ - The new name of the directory. Defaults to the current name if unspecified. _(DOMString)_ +- __successCallback__ - A callback that is called with the DirectoryEntry object of the new directory. _(Function)_ +- __errorCallback__ - A callback that is called if an error occurs when attempting to move the directory. Invoked with a FileError object. _(Function)_ + + +__Quick Example__ + + function success(entry) { + console.log("New Path: " + entry.fullPath); + } + + function fail(error) { + alert(error.code); + } + + function moveDir(entry) { + var parent = document.getElementById('parent').value, + parentName = parent.substring(parent.lastIndexOf('/')+1), + newName = document.getElementById('newName').value, + parentEntry = new DirectoryEntry(parentName, parent); + + // move the directory to a new directory and rename it + entry.moveTo(parentEntry, newName, success, fail); + } + +copyTo +------ + +Copy a directory to a different location on the file system. It is an error to attempt to: + +- copy a directory inside itself at any depth; +- copy a directory into its parent if a name different from its current one is not provided. + +Directory copies are always recursive - that is, they copy all contents of the directory. + +__Parameters:__ + +- __parent__ - The parent directory to which to copy the directory. _(DirectoryEntry)_ +- __newName__ - The new name of the directory. Defaults to the current name if unspecified. _(DOMString)_ +- __successCallback__ - A callback that is called with the DirectoryEntry object of the new directory. _(Function)_ +- __errorCallback__ - A callback that is called if an error occurs when attempting to copy the underlying directory. Invoked with a FileError object. _(Function)_ + + +__Quick Example__ + + function win(entry) { + console.log("New Path: " + entry.fullPath); + } + + function fail(error) { + alert(error.code); + } + + function copyDir(entry) { + var parent = document.getElementById('parent').value, + parentName = parent.substring(parent.lastIndexOf('/')+1), + newName = document.getElementById('newName').value, + parentEntry = new DirectoryEntry(parentName, parent); + + // copy the directory to a new directory and rename it + entry.copyTo(parentEntry, newName, success, fail); + } + + +toURL +----- + +Returns a URL that can be used to locate the directory. + +__Quick Example__ + + // Get the URL for this directory + var dirURL = entry.toURL(); + console.log(dirURL); + + +remove +------ + +Deletes a directory. It is an error to attempt to: + +- delete a directory that is not empty; +- delete the root directory of a filesystem. + +__Parameters:__ + +- __successCallback__ - A callback that is called after the directory has been deleted. Invoked with no parameters. _(Function)_ +- __errorCallback__ - A callback that is called if an error occurs when attempting to delete the directory. Invoked with a FileError object. _(Function)_ + +__Quick Example__ + + function success(entry) { + console.log("Removal succeeded"); + } + + function fail(error) { + alert('Error removing directory: ' + error.code); + } + + // remove this directory + entry.remove(success, fail); + + +getParent +--------- + +Look up the parent DirectoryEntry containing the directory. + +__Parameters:__ + +- __successCallback__ - A callback that is called with the directory's parent DirectoryEntry. _(Function)_ +- __errorCallback__ - A callback that is called if an error occurs when attempting to retrieve the parent DirectoryEntry. Invoked with a FileError object. _(Function)_ + +__Quick Example__ + + function success(parent) { + console.log("Parent Name: " + parent.name); + } + + function fail(error) { + alert('Failed to get parent directory: ' + error.code); + } + + // Get the parent DirectoryEntry + entry.getParent(success, fail); + + +createReader +------------ + +Creates a new DirectoryReader to read entries in a directory. + +__Quick Example__ + + // create a directory reader + var directoryReader = entry.createReader(); + + +getDirectory +------------ + +Creates or looks up an existing directory. It is an error to attempt to: + +- create a directory whose immediate parent does not yet exist. + +__Parameters:__ + +- __path__ - The path to the directory to be looked up or created. Either an absolute path, or a relative path from this DirectoryEntry. _(DOMString)_ +- __options__ - Options to specify whether the directory is created if it doesn't exist. _(Flags)_ +- __successCallback__ - A callback that is invoked with a DirectoryEntry object. _(Function)_ +- __errorCallback__ - A callback that is called if an error occurs creating or looking up the directory. Invoked with a FileError object. _(Function)_ + +__Quick Example__ + + function success(parent) { + console.log("Parent Name: " + parent.name); + } + + function fail(error) { + alert("Unable to create new directory: " + error.code); + } + + // Retrieve an existing directory, or create it if it does not already exist + entry.getDirectory("newDir", {create: true, exclusive: false}, success, fail); + + +getFile +------- + +Creates or looks up a file. It is an error to attempt to: + +- create a file whose immediate parent does not yet exist. + +__Parameters:__ + +- __path__ - The path to the file to be looked up or created. Either an absolute path, or a relative path from this DirectoryEntry. _(DOMString)_ +- __options__ - Options to specify whether the file is created if it doesn't exist. _(Flags)_ +- __successCallback__ - A callback that is invoked with a FileEntry object. _(Function)_ +- __errorCallback__ - A callback that is called if an error occurs creating or looking up the file. Invoked with a FileError object. _(Function)_ + +__Quick Example__ + + function success(parent) { + console.log("Parent Name: " + parent.name); + } + + function fail(error) { + alert("Failed to retrieve file: " + error.code); + } + + // Retrieve an existing file, or create it if it does not exist + entry.getFile("newFile.txt", {create: true, exclusive: false}, success, fail); + + +removeRecursively +----------------- + +Deletes a directory and all of its contents. In the event of an error (e.g. trying to delete +a directory that contains a file that cannot be removed), some of the contents of the directory may +be deleted. It is an error to attempt to: + +- delete the root directory of a filesystem. + +__Parameters:__ + +- __successCallback__ - A callback that is called after the DirectoryEntry has been deleted. Invoked with no parameters. _(Function)_ +- __errorCallback__ - A callback that is called if an error occurs when attempting to delete the DirectoryEntry. Invoked with a FileError object. _(Function)_ + +__Quick Example__ + + function success(parent) { + console.log("Remove Recursively Succeeded"); + } + + function fail(error) { + alert("Failed to remove directory or it's contents: " + error.code); + } + + // remove the directory and all it's contents + entry.removeRecursively(success, fail); + +BlackBerry Quirks +----------------- + +May fail with a ControlledAccessException in the following cases: + +- Access is attempted on an directory created by a previous installation of an application. + +> solution: insure temporary directories are cleaned manually, or by the application before reinstall + +- if device is connected by usb + +> solution: disconnect usb cable from device and run again http://git-wip-us.apache.org/repos/asf/cordova-docs/blob/40331cf8/docs/en/2.8.0rc1/edge/cordova/file/directoryreader/directoryreader.md ---------------------------------------------------------------------- diff --git a/docs/en/2.8.0rc1/edge/cordova/file/directoryreader/directoryreader.md b/docs/en/2.8.0rc1/edge/cordova/file/directoryreader/directoryreader.md new file mode 100644 index 0000000..ad69669 --- /dev/null +++ b/docs/en/2.8.0rc1/edge/cordova/file/directoryreader/directoryreader.md @@ -0,0 +1,67 @@ +--- +license: Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--- + +DirectoryReader +=============== + +An object that lists files and directories in a directory. Defined in the [Directories and Systems](http://www.w3.org/TR/file-system-api/) specification. + +Methods +------- + +- __readEntries__: Read the entries in a directory. + + +Supported Platforms +------------------- + +- Android +- BlackBerry WebWorks (OS 5.0 and higher) +- iOS +- Windows Phone 7 and 8 +- Windows 8 + +readEntries +----------- + +Read the entries in this directory. + +__Parameters:__ + +- __successCallback__ - A callback that is passed an array of FileEntry and DirectoryEntry objects. _(Function)_ +- __errorCallback__ - A callback that is called if an error occurs retrieving the directory listing. Invoked with a FileError object. _(Function)_ + +__Quick Example__ + + function success(entries) { + var i; + for (i=0; i This API is based on the W3C [File API](http://www.w3.org/TR/FileAPI). An API to read, write and navigate file system hierarchies. + +Objects +------- + +- DirectoryEntry +- DirectoryReader +- File +- FileEntry +- FileError +- FileReader +- FileSystem +- FileTransfer +- FileTransferError +- FileUploadOptions +- FileUploadResult +- FileWriter +- Flags +- LocalFileSystem +- Metadata + +Permissions +----------- + +### Android + +#### app/res/xml/config.xml + + + + +#### app/AndroidManifest.xml + + + +### Bada + + No permissions are required. + +### BlackBerry WebWorks + +#### www/plugins.xml + + + + +#### www/config.xml + + + + + + access_shared + + +### iOS + +#### config.xml + + + + +### webOS + + No permissions are required. + +### Windows Phone + + No permissions are required. http://git-wip-us.apache.org/repos/asf/cordova-docs/blob/40331cf8/docs/en/2.8.0rc1/edge/cordova/file/fileentry/fileentry.md ---------------------------------------------------------------------- diff --git a/docs/en/2.8.0rc1/edge/cordova/file/fileentry/fileentry.md b/docs/en/2.8.0rc1/edge/cordova/file/fileentry/fileentry.md new file mode 100644 index 0000000..474fd68 --- /dev/null +++ b/docs/en/2.8.0rc1/edge/cordova/file/fileentry/fileentry.md @@ -0,0 +1,327 @@ +--- +license: Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--- + +FileEntry +========== + +This object represents a file on a file system. It is defined in the [W3C Directories and Systems](http://www.w3.org/TR/file-system-api/) specification. + +Properties +---------- + +- __isFile:__ Always true. _(boolean)_ +- __isDirectory:__ Always false. _(boolean)_ +- __name:__ The name of the FileEntry, excluding the path leading to it. _(DOMString)_ +- __fullPath:__ The full absolute path from the root to the FileEntry. _(DOMString)_ + +NOTE: The following attributes are defined by the W3C specification, but are __not supported__ by Cordova: + +- __filesystem:__ The file system on which the FileEntry resides. _(FileSystem)_ + + +Methods +------- + +- __getMetadata__: Look up metadata about a file. +- __setMetadata__: Set metadata on a file. +- __moveTo__: Move a file to a different location on the file system. +- __copyTo__: Copy a file to a different location on the file system. +- __toURL__: Return a URL that can be used to locate a file. +- __remove__: Delete a file. +- __getParent__: Look up the parent directory. +- __createWriter__: Creates a FileWriter object that can be used to write to a file. +- __file__: Creates a File object containing file properties. + + +Supported Platforms +------------------- + +- Android +- BlackBerry WebWorks (OS 5.0 and higher) +- iOS +- Windows Phone 7 and 8 +- Windows 8 + + +getMetadata +---------------- + +Look up metadata about a file. + +__Parameters:__ + +- __successCallback__ - A callback that is called with a Metadata object. _(Function)_ +- __errorCallback__ - A callback that is called if an error occurs retrieving the Metadata. Invoked with a FileError object. _(Function)_ + + +__Quick Example__ + + function success(metadata) { + console.log("Last Modified: " + metadata.modificationTime); + } + + function fail(error) { + alert(error.code); + } + + // Request the metadata object for this entry + entry.getMetadata(success, fail); + + +setMetadata +---------------- + +Set metadata on a file. +**Only works on iOS currently** - this will set the extended attributes of a file. + +__Parameters:__ + +- __successCallback__ - A callback that is called when the metadata was successfully set. _(Function)_ +- __errorCallback__ - A callback that is called when the metadata was not successfully set. _(Function)_ +- __metadataObject__ - An object that contains the metadata keys and values. _(Object)_ + + +__Quick Example__ + + function success() { + console.log("The metadata was successfully set."); + } + + function fail() { + alert("There was an error in setting the metadata"); + } + + // Set the metadata + entry.setMetadata(success, fail, { "com.apple.MobileBackup": 1}); +__iOS Quirk__ + +- only the **"com.apple.MobileBackup"** extended attribute is supported. Set the value to **1** to NOT enable the file to be backed up by iCloud. Set the value to **0** to re-enable the file to be backed up by iCloud. + +__Quick Example__ + + function setFileMetadata(localFileSystem, filePath, metadataKey, metadataValue) + { + var onSetMetadataWin = function() { + console.log("success setting metadata") + } + var onSetMetadataFail = function() { + console.log("error setting metadata") + } + + var onGetFileWin = function(parent) { + var data = {}; + data[metadataKey] = metadataValue; + parent.setMetadata(onSetMetadataWin, onSetMetadataFail, data); + } + var onGetFileFail = function() { + console.log("error getting file") + } + + var onFSWin = function(fileSystem) { + fileSystem.root.getFile(filePath, {create: true, exclusive: false}, onGetFileWin, onGetFileFail); + } + + var onFSFail = function(evt) { + console.log(evt.target.error.code); + } + + window.requestFileSystem(localFileSystem, 0, onFSWin, onFSFail); + } + + setFileMetadata(LocalFileSystem.PERSISTENT, "Backups/sqlite.db", "com.apple.MobileBackup", 1); + +moveTo +------ + +Move a file to a different location on the file system. It is an error to attempt to: + +- move a file into its parent if a name different from its current one isn't provided; +- move a file to a path occupied by a directory; + +In addition, an attempt to move a file on top of an existing file must attempt to delete and replace that file. + +__Parameters:__ + +- __parent__ - The parent directory to which to move the file. _(DirectoryEntry)_ +- __newName__ - The new name of the file. Defaults to the current name if unspecified. _(DOMString)_ +- __successCallback__ - A callback that is called with the FileEntry object of the new file. _(Function)_ +- __errorCallback__ - A callback that is called if an error occurs when attempting to move the file. Invoked with a FileError object. _(Function)_ + + +__Quick Example__ + + function success(entry) { + console.log("New Path: " + entry.fullPath); + } + + function fail(error) { + alert(error.code); + } + + function moveFile(entry) { + var parent = document.getElementById('parent').value, + parentName = parent.substring(parent.lastIndexOf('/')+1), + parentEntry = new DirectoryEntry(parentName, parent); + + // move the file to a new directory and rename it + entry.moveTo(parentEntry, "newFile.txt", success, fail); + } + + +copyTo +------ + +Copy a file to a new location on the file system. It is an error to attempt to: + +- copy a file into its parent if a name different from its current one is not provided. + +__Parameters:__ + +- __parent__ - The parent directory to which to copy the file. _(DirectoryEntry)_ +- __newName__ - The new name of the file. Defaults to the current name if unspecified. _(DOMString)_ +- __successCallback__ - A callback that is called with the FileEntry object of the new file. _(Function)_ +- __errorCallback__ - A callback that is called if an error occurs when attempting to copy the file. Invoked with a FileError object. _(Function)_ + + +__Quick Example__ + + function win(entry) { + console.log("New Path: " + entry.fullPath); + } + + function fail(error) { + alert(error.code); + } + + function copyFile(entry) { + var parent = document.getElementById('parent').value, + parentName = parent.substring(parent.lastIndexOf('/')+1), + parentEntry = new DirectoryEntry(parentName, parent); + + // copy the file to a new directory and rename it + entry.copyTo(parentEntry, "file.copy", success, fail); + } + + +toURL +----- + +Returns a URL that can be used to locate the file. + +__Quick Example__ + + // Request the URL for this entry + var fileURL = entry.toURL(); + console.log(fileURL); + + +remove +------ + +Deletes a file. + +__Parameters:__ + +- __successCallback__ - A callback that is called after the file has been deleted. Invoked with no parameters. _(Function)_ +- __errorCallback__ - A callback that is called if an error occurs when attempting to delete the file. Invoked with a FileError object. _(Function)_ + +__Quick Example__ + + function success(entry) { + console.log("Removal succeeded"); + } + + function fail(error) { + alert('Error removing file: ' + error.code); + } + + // remove the file + entry.remove(success, fail); + + +getParent +--------- + +Look up the parent DirectoryEntry containing the file. + +__Parameters:__ + +- __successCallback__ - A callback that is called with the file's parent DirectoryEntry. _(Function)_ +- __errorCallback__ - A callback that is called if an error occurs when attempting to retrieve the parent DirectoryEntry. Invoked with a FileError object. _(Function)_ + +__Quick Example__ + + function success(parent) { + console.log("Parent Name: " + parent.name); + } + + function fail(error) { + alert(error.code); + } + + // Get the parent DirectoryEntry + entry.getParent(success, fail); + + +createWriter +------------ + +Create a FileWriter object associated with the file that the FileEntry represents. + +__Parameters:__ + +- __successCallback__ - A callback that is called with a FileWriter object. _(Function)_ +- __errorCallback__ - A callback that is called if an error occurs while attempting to create the FileWriter. Invoked with a FileError object. _(Function)_ + +__Quick Example__ + + function success(writer) { + writer.write("Some text to the file"); + } + + function fail(error) { + alert(error.code); + } + + // create a FileWriter to write to the file + entry.createWriter(success, fail); + + +file +---- + +Return a File object that represents the current state of the file that this FileEntry represents. + +__Parameters:__ + +- __successCallback__ - A callback that is called with a File object. _(Function)_ +- __errorCallback__ - A callback that is called if an error occurs when creating the File object (e.g. the underlying file no longer exists). Invoked with a FileError object. _(Function)_ + +__Quick Example__ + + function success(file) { + console.log("File size: " + file.size); + } + + function fail(error) { + alert("Unable to retrieve file properties: " + error.code); + } + + // obtain properties of a file + entry.file(success, fail); http://git-wip-us.apache.org/repos/asf/cordova-docs/blob/40331cf8/docs/en/2.8.0rc1/edge/cordova/file/fileerror/fileerror.md ---------------------------------------------------------------------- diff --git a/docs/en/2.8.0rc1/edge/cordova/file/fileerror/fileerror.md b/docs/en/2.8.0rc1/edge/cordova/file/fileerror/fileerror.md new file mode 100644 index 0000000..75511c5 --- /dev/null +++ b/docs/en/2.8.0rc1/edge/cordova/file/fileerror/fileerror.md @@ -0,0 +1,49 @@ +--- +license: Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--- + +FileError +======== + +A 'FileError' object is set when an error occurs in any of the File API methods. + +Properties +---------- + +- __code:__ One of the predefined error codes listed below. + +Constants +--------- + +- `FileError.NOT_FOUND_ERR` +- `FileError.SECURITY_ERR` +- `FileError.ABORT_ERR` +- `FileError.NOT_READABLE_ERR` +- `FileError.ENCODING_ERR` +- `FileError.NO_MODIFICATION_ALLOWED_ERR` +- `FileError.INVALID_STATE_ERR` +- `FileError.SYNTAX_ERR` +- `FileError.INVALID_MODIFICATION_ERR` +- `FileError.QUOTA_EXCEEDED_ERR` +- `FileError.TYPE_MISMATCH_ERR` +- `FileError.PATH_EXISTS_ERR` + +Description +----------- + +The `FileError` object is the only parameter of any of the File API's error callbacks. Developers must read the code property to determine the type of error. \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cordova-docs/blob/40331cf8/docs/en/2.8.0rc1/edge/cordova/file/fileobj/fileobj.md ---------------------------------------------------------------------- diff --git a/docs/en/2.8.0rc1/edge/cordova/file/fileobj/fileobj.md b/docs/en/2.8.0rc1/edge/cordova/file/fileobj/fileobj.md new file mode 100644 index 0000000..a24ff82 --- /dev/null +++ b/docs/en/2.8.0rc1/edge/cordova/file/fileobj/fileobj.md @@ -0,0 +1,81 @@ +--- +license: Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--- + +File +==== + +This object contains attributes of a single file. + +Properties +---------- + +- __name:__ The name of the file. _(DOMString)_ +- __fullPath:__ The full path of the file including the file name. _(DOMString)_ +- __type:__ The mime type of the file. _(DOMString)_ +- __lastModifiedDate:__ The last time the file was modified. _(Date)_ +- __size:__ The size of the file in bytes. _(long)_ + +Methods +------- + +- __slice__: Select only a portion of the file to be read. + +Details +------- + +The `File` object contains attributes of a single file. You can get an instance of a File object by calling the __file__ method of a `FileEntry` object. + +Supported Platforms +------------------- + +- Android +- BlackBerry WebWorks (OS 5.0 and higher) +- iOS +- Windows Phone 7 and 8 +- Windows 8 + + +slice +-------------- + +Return a new File object, for which FileReader will return only the specified portion of the file. +Negative values for __start__ or __end__ are measured from the end of the file. +The indexes are always relative to the current slice (see the full example). + +__Parameters:__ + +- __start__ - The index of the first byte to read, inclusive. +- __end__ - The index of the byte after the last one to read. + +__Quick Example__ + + var slicedFile = file.slice(10, 30); + +__Full Example__ + + var slice1 = file.slice(100, 400); + var slice2 = slice1.slice(20, 35); + + var slice3 = file.slice(120, 135); + // slice2 and slice3 are equivalent. + +__Supported Platforms:__ + +- Android +- iOS http://git-wip-us.apache.org/repos/asf/cordova-docs/blob/40331cf8/docs/en/2.8.0rc1/edge/cordova/file/filereader/filereader.md ---------------------------------------------------------------------- diff --git a/docs/en/2.8.0rc1/edge/cordova/file/filereader/filereader.md b/docs/en/2.8.0rc1/edge/cordova/file/filereader/filereader.md new file mode 100644 index 0000000..1cc6cfb --- /dev/null +++ b/docs/en/2.8.0rc1/edge/cordova/file/filereader/filereader.md @@ -0,0 +1,255 @@ +--- +license: Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--- + +FileReader +========== + +FileReader is an object that allows one to read a file. + +Properties +---------- + +- __readyState:__ One of the three states the reader can be in EMPTY, LOADING or DONE. +- __result:__ The contents of the file that has been read. _(DOMString)_ +- __error:__ An object containing errors. _(FileError)_ +- __onloadstart:__ Called when the read starts. . _(Function)_ +- __onprogress:__ Called while reading the file, reports progress (progess.loaded/progress.total). _(Function)_ -NOT SUPPORTED +- __onload:__ Called when the read has successfully completed. _(Function)_ +- __onabort:__ Called when the read has been aborted. For instance, by invoking the abort() method. _(Function)_ +- __onerror:__ Called when the read has failed. _(Function)_ +- __onloadend:__ Called when the request has completed (either in success or failure). _(Function)_ + +Methods +------- + +- __abort__: Aborts reading file. +- __readAsDataURL__: Read file and return data as a base64 encoded data url. +- __readAsText__: Reads text file. +- __readAsBinaryString__: Reads file as binary and returns a binary string. +- __readAsArrayBuffer__: Reads file as an ArrayBuffer. + +Details +------- + +The `FileReader` object is a way to read files from the devices file system. Files can be read as text or as a base64 data encoded string. Users register their own event listeners to receive the loadstart, progress, load, loadend, error and abort events. + +Supported Platforms +------------------- + +- Android +- BlackBerry WebWorks (OS 5.0 and higher) +- iOS +- Windows Phone 7 and 8 +- Windows 8 + +Read As Data URL +---------------- + +__Parameters:__ +- file - the file object to read + + +Quick Example +------------- + + function win(file) { + var reader = new FileReader(); + reader.onloadend = function(evt) { + console.log("read success"); + console.log(evt.target.result); + }; + reader.readAsDataURL(file); + }; + + var fail = function(evt) { + console.log(error.code); + }; + + entry.file(win, fail); + +Read As Text +------------ + +__Parameters:__ + +- file - the file object to read +- encoding - the encoding to use to encode the file's content. Default is UTF8. + +Quick Example +------------- + + function win(file) { + var reader = new FileReader(); + reader.onloadend = function(evt) { + console.log("read success"); + console.log(evt.target.result); + }; + reader.readAsText(file); + }; + + var fail = function(evt) { + console.log(error.code); + }; + + entry.file(win, fail); + +Abort Quick Example +------------------- + + function win(file) { + var reader = new FileReader(); + reader.onloadend = function(evt) { + console.log("read success"); + console.log(evt.target.result); + }; + reader.readAsText(file); + reader.abort(); + }; + + function fail(error) { + console.log(error.code); + } + + entry.file(win, fail); + +Full Example +------------ + + + + + FileReader Example + + + + + +

Example

+

Read File

+ + + +iOS Quirks +---------- +- __encoding__ parameter is not supported, UTF8 encoding is always used. + +Read As Binary String +--------------------- + +Currently supported on iOS and Android only. + +__Parameters:__ +- file - the file object to read + + +Quick Example +------------- + + function win(file) { + var reader = new FileReader(); + reader.onloadend = function(evt) { + console.log("read success"); + console.log(evt.target.result); + }; + reader.readAsBinaryString(file); + }; + + var fail = function(evt) { + console.log(error.code); + }; + + entry.file(win, fail); + + +Read As Array Buffer +-------------------- + +Currently supported on iOS and Android only. + +__Parameters:__ +- file - the file object to read + + +Quick Example +------------- + + function win(file) { + var reader = new FileReader(); + reader.onloadend = function(evt) { + console.log("read success"); + console.log(new Uint8Array(evt.target.result)); + }; + reader.readAsArrayBuffer(file); + }; + + var fail = function(evt) { + console.log(error.code); + }; + + entry.file(win, fail); + http://git-wip-us.apache.org/repos/asf/cordova-docs/blob/40331cf8/docs/en/2.8.0rc1/edge/cordova/file/filesystem/filesystem.md ---------------------------------------------------------------------- diff --git a/docs/en/2.8.0rc1/edge/cordova/file/filesystem/filesystem.md b/docs/en/2.8.0rc1/edge/cordova/file/filesystem/filesystem.md new file mode 100644 index 0000000..f51dd41 --- /dev/null +++ b/docs/en/2.8.0rc1/edge/cordova/file/filesystem/filesystem.md @@ -0,0 +1,92 @@ +--- +license: Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--- + +FileSystem +========== + +This object represents a file system. + +Properties +---------- + +- __name:__ The name of the file system. _(DOMString)_ +- __root:__ The root directory of the file system. _(DirectoryEntry)_ + +Details +------- + +The `FileSystem` object represents information about the file system. The name of the file system will be unique across the list of exposed file systems. The root property contains a `DirectoryEntry` object which represents the root directory of the file system. + +Supported Platforms +------------------- + +- Android +- BlackBerry WebWorks (OS 5.0 and higher) +- iOS +- Windows Phone 7 and 8 +- Windows 8 + +File System Quick Example +------------------------- + + function onSuccess(fileSystem) { + console.log(fileSystem.name); + console.log(fileSystem.root.name); + } + + // request the persistent file system + window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onSuccess, null); + +Full Example +------------ + + + + + File System Example + + + + + +

Example

+

File System

+ + http://git-wip-us.apache.org/repos/asf/cordova-docs/blob/40331cf8/docs/en/2.8.0rc1/edge/cordova/file/filetransfer/filetransfer.md ---------------------------------------------------------------------- diff --git a/docs/en/2.8.0rc1/edge/cordova/file/filetransfer/filetransfer.md b/docs/en/2.8.0rc1/edge/cordova/file/filetransfer/filetransfer.md new file mode 100644 index 0000000..fdcd9d6 --- /dev/null +++ b/docs/en/2.8.0rc1/edge/cordova/file/filetransfer/filetransfer.md @@ -0,0 +1,292 @@ +--- +license: Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--- + +FileTransfer +========== + +FileTransfer is an object that allows you to upload files to a server or download files from a server. + +Properties +---------- + +- __onprogress:__ Called with a ProgressEvent whenever a new chunk of data is transferred. _(Function)_ + +Methods +------- + +- __upload__: sends a file to a server. +- __download__: downloads a file from server. +- __abort__: Aborts an in-progress transfer. + +Details +------- + +The `FileTransfer` object provides a way to upload files to a remote server using an HTTP multi-part POST request. Both HTTP and HTTPS protocols are supported. Optional parameters can be specified by passing a FileUploadOptions object to the upload method. On successful upload, the success callback will be called with a FileUploadResult object. If an error occurs, the error callback will be invoked with a FileTransferError object. +It is also possible to download a file from remote and save it on the device (only iOS and Android). + +Supported Platforms +------------------- + +- Android +- BlackBerry WebWorks (OS 5.0 and higher) +- iOS +- Windows Phone 7 and 8 +- Windows 8 + +upload +-------------- + +__Parameters:__ + +- __filePath__ - Full path of the file on the device +- __server__ - URL of the server to receive the file (must already be encoded using encodeURI()) +- __successCallback__ - A callback that is called with a Metadata object. _(Function)_ +- __errorCallback__ - A callback that is called if an error occurs retrieving the Metadata. Invoked with a FileTransferError object. _(Function)_ +- __options__ - Optional parameters such as file name and mimetype +- __trustAllHosts__ - Optional parameter, defaults to false. If set to true then it will accept all security certificates. This is useful as Android rejects self signed security certificates. Not recommended for production use. Supported on Android and iOS. _(boolean)_ + +__Quick Example__ + + // !! Assumes variable fileURI contains a valid URI to a text file on the device + + var win = function(r) { + console.log("Code = " + r.responseCode); + console.log("Response = " + r.response); + console.log("Sent = " + r.bytesSent); + } + var fail = function(error) { + alert("An error has occurred: Code = " + error.code); + console.log("upload error source " + error.source); + console.log("upload error target " + error.target); + } + + var options = new FileUploadOptions(); + options.fileKey="file"; + options.fileName=fileURI.substr(fileURI.lastIndexOf('/')+1); + options.mimeType="text/plain"; + + var params = {}; + params.value1 = "test"; + params.value2 = "param"; + + options.params = params; + + var ft = new FileTransfer(); + ft.upload(fileURI, encodeURI("http://some.server.com/upload.php"), win, fail, options); + +__Full Example__ + + + + + File Transfer Example + + + + + +

Example

+

Upload File

+ + + +__Setting Upload Headers__ + +Supported on Android and iOS + + function win(r) { + console.log("Code = " + r.responseCode); + console.log("Response = " + r.response); + console.log("Sent = " + r.bytesSent); + } + + function fail(error) { + alert("An error has occurred: Code = " + error.code); + console.log("upload error source " + error.source); + console.log("upload error target " + error.target); + } + + var uri = encodeURI("http://some.server.com/upload.php"); + + var options = new FileUploadOptions(); + options.fileKey="file"; + options.fileName=fileURI.substr(fileURI.lastIndexOf('/')+1); + options.mimeType="text/plain"; + + var headers={'headerParam':'headerValue'}; + + options.headers = headers; + + var ft = new FileTransfer(); + ft.upload(fileURI, uri, win, fail, options); + +__Android Quirks__ + +If you experience problems uploading to a Nginx server then make sure you have the chunkedMode option set to false. + +download +-------------- + +__Parameters:__ + +- __source__ - URL of the server to download the file (must already be encoded using encodeURI()) +- __target__ - Full path of the file on the device +- __successCallback__ - A callback that is called with a FileEntry object. _(Function)_ +- __errorCallback__ - A callback that is called if an error occurs retrieving the Metadata. Invoked with a FileTransferError object. _(Function)_ +- __trustAllHosts__ - Optional parameter, defaults to false. If set to true then it will accept all security certificates. This is useful as Android rejects self signed security certificates. Not recommended for production use. Supported on Android and iOS. _(boolean)_ +- __options__ - Optional parameters, currently only supports headers (such as Authorization (Basic Authentication), etc). + +__Quick Example__ + + // !! 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==" + } + } + ); + +abort +-------------- + +Aborts an in-progress transfer. The onerror callback will be called with a FileTransferError object which has an error code of FileTransferError.ABORT_ERR. + +__Supported Platforms__ + +- Android +- iOS + +__Quick Example__ + + // !! Assumes variable fileURI contains a valid URI to a text file on the device + + var win = function(r) { + console.log("Code = " + r.responseCode); + console.log("Response = " + r.response); + console.log("Sent = " + r.bytesSent); + } + + var fail = function(error) { + alert("An error has occurred: Code = " + error.code); + console.log("upload error source " + error.source); + console.log("upload error target " + error.target); + } + + var options = new FileUploadOptions(); + options.fileKey="file"; + options.fileName=fileURI.substr(fileURI.lastIndexOf('/')+1); + options.mimeType="text/plain"; + + var params = {}; + params.value1 = "test"; + params.value2 = "param"; + + options.params = params; + + var ft = new FileTransfer(); + ft.upload(fileURI, encodeURI("http://some.server.com/upload.php"), win, fail, options); + ft.abort(win, fail); + +onprogress +-------------- + +Called with a ProgressEvent whenever a new chunk of data is transferred. + +__Supported Platforms__ + +- Android +- iOS + +__Example__ + + fileTransfer.onprogress = function(progressEvent) { + if (progressEvent.lengthComputable) { + loadingStatus.setPercentage(progressEvent.loaded / progressEvent.total); + } else { + loadingStatus.increment(); + } + }; + fileTransfer.download(...); // or fileTransfer.upload(...); + +__Quirks__ +- On both Android an iOS, lengthComputable is false for downloads that use gzip encoding. http://git-wip-us.apache.org/repos/asf/cordova-docs/blob/40331cf8/docs/en/2.8.0rc1/edge/cordova/file/filetransfererror/filetransfererror.md ---------------------------------------------------------------------- diff --git a/docs/en/2.8.0rc1/edge/cordova/file/filetransfererror/filetransfererror.md b/docs/en/2.8.0rc1/edge/cordova/file/filetransfererror/filetransfererror.md new file mode 100644 index 0000000..568c161 --- /dev/null +++ b/docs/en/2.8.0rc1/edge/cordova/file/filetransfererror/filetransfererror.md @@ -0,0 +1,45 @@ +--- +license: Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--- + +FileTransferError +======== + +A `FileTransferError` object is returned via the error callback when an error occurs. + +Properties +---------- + +- __code__ One of the predefined error codes listed below. (Number) +- __source__ URI to the source (String) +- __target__ URI to the target (String) +- __http_status__ HTTP status code. This attribute is only available when a response code is received from the HTTP connection. (Number) +- __body__ Response body. This attribute is only available when a response is received from the HTTP connection. Available only on Android, iOS. (String) + +Constants +--------- + +- `FileTransferError.FILE_NOT_FOUND_ERR` +- `FileTransferError.INVALID_URL_ERR` +- `FileTransferError.CONNECTION_ERR` +- `FileTransferError.ABORT_ERR` + +Description +----------- + +The `FileTransferError` object is returned via the error callback when an error occurs when uploading or downloading a file. http://git-wip-us.apache.org/repos/asf/cordova-docs/blob/40331cf8/docs/en/2.8.0rc1/edge/cordova/file/fileuploadoptions/fileuploadoptions.md ---------------------------------------------------------------------- diff --git a/docs/en/2.8.0rc1/edge/cordova/file/fileuploadoptions/fileuploadoptions.md b/docs/en/2.8.0rc1/edge/cordova/file/fileuploadoptions/fileuploadoptions.md new file mode 100644 index 0000000..5246ce8 --- /dev/null +++ b/docs/en/2.8.0rc1/edge/cordova/file/fileuploadoptions/fileuploadoptions.md @@ -0,0 +1,45 @@ +--- +license: Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--- + +FileUploadOptions +======== + +A `FileUploadOptions` object can be passed to the FileTransfer objects upload method in order to specify additional parameters to the upload script. + +Properties +---------- + +- __fileKey:__ The name of the form element. If not set defaults to "file". (DOMString) +- __fileName:__ The file name you want the file to be saved as on the server. If not set defaults to "image.jpg". (DOMString) +- __mimeType:__ The mime type of the data you are uploading. If not set defaults to "image/jpeg". (DOMString) +- __params:__ A set of optional key/value pairs to be passed along in the HTTP request. (Object) +- __chunkedMode:__ Should the data be uploaded in chunked streaming mode. If not set defaults to "true". (Boolean) +- __headers:__ A map of header name => header value. To specify multiple values for a header, use an array of values. (Object) + + +Description +----------- + +A `FileUploadOptions` object can be passed to the FileTransfer objects upload method in order to specify additional parameters to the upload script. + +WP7 Quirk +--------- + +- __chunkedMode:__ + This parameter is ignored on WP7. http://git-wip-us.apache.org/repos/asf/cordova-docs/blob/40331cf8/docs/en/2.8.0rc1/edge/cordova/file/fileuploadresult/fileuploadresult.md ---------------------------------------------------------------------- diff --git a/docs/en/2.8.0rc1/edge/cordova/file/fileuploadresult/fileuploadresult.md b/docs/en/2.8.0rc1/edge/cordova/file/fileuploadresult/fileuploadresult.md new file mode 100644 index 0000000..f21d036 --- /dev/null +++ b/docs/en/2.8.0rc1/edge/cordova/file/fileuploadresult/fileuploadresult.md @@ -0,0 +1,40 @@ +--- +license: Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--- + +FileUploadResult +======== + +A `FileUploadResult` object is returned via the success callback of the FileTransfer upload method. + +Properties +---------- + +- __bytesSent:__ The number of bytes sent to the server as part of the upload. (long) +- __responseCode:__ The HTTP response code returned by the server. (long) +- __response:__ The HTTP response returned by the server. (DOMString) + +Description +----------- + +The `FileUploadResult` object is returned via the success callback of the FileTransfer upload method. + +iOS Quirks +---------- +- iOS does not include values for responseCode nor bytesSent in the success callback FileUploadResult object. + http://git-wip-us.apache.org/repos/asf/cordova-docs/blob/40331cf8/docs/en/2.8.0rc1/edge/cordova/file/filewriter/filewriter.md ---------------------------------------------------------------------- diff --git a/docs/en/2.8.0rc1/edge/cordova/file/filewriter/filewriter.md b/docs/en/2.8.0rc1/edge/cordova/file/filewriter/filewriter.md new file mode 100644 index 0000000..a7c2976 --- /dev/null +++ b/docs/en/2.8.0rc1/edge/cordova/file/filewriter/filewriter.md @@ -0,0 +1,195 @@ +--- +license: Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--- + +FileWriter +========== + +FileWriter is an object that allows one to write a file. + +Properties +---------- + +- __readyState:__ One of the three states the reader can be in INIT, WRITING or DONE. +- __fileName:__ The name of the file to be written. _(DOMString)_ +- __length:__ The length of the file to be written. _(long)_ +- __position:__ The current position of the file pointer. _(long)_ +- __error:__ An object containing errors. _(FileError)_ +- __onwritestart:__ Called when the write starts. . _(Function)_ +- __onprogress:__ Called while writing the file, reports progress (progress.loaded/progress.total). _(Function)_ -NOT SUPPORTED +- __onwrite:__ Called when the request has completed successfully. _(Function)_ +- __onabort:__ Called when the write has been aborted. For instance, by invoking the abort() method. _(Function)_ +- __onerror:__ Called when the write has failed. _(Function)_ +- __onwriteend:__ Called when the request has completed (either in success or failure). _(Function)_ + +Methods +------- + +- __abort__: Aborts writing file. +- __seek__: Moves the file pointer to the byte specified. +- __truncate__: Shortens the file to the length specified. +- __write__: Writes data to the file with a UTF-8 encoding. + +Details +------- + +The `FileWriter` object is a way to write files to the device file system (UTF-8 encoded). Users register their own event listeners to receive the writestart, progress, write, writeend, error and abort events. + +A FileWriter is created for a single file. You can use it to write to a file multiple times. The FileWriter maintains the file's position and length attributes, so you can seek and write anywhere in the file. By default, the FileWriter writes to the beginning of the file (will overwrite existing data). Set the optional append boolean to true in the FileWriter's constructor to begin writing to the end of the file. + +Supported Platforms +------------------- + +- Android +- BlackBerry WebWorks (OS 5.0 and higher) +- iOS +- Windows Phone 7 and 8 +- Windows 8 + +Seek Quick Example +------------------------------ + + function win(writer) { + // fast forwards file pointer to end of file + writer.seek(writer.length); + }; + + var fail = function(evt) { + console.log(error.code); + }; + + entry.createWriter(win, fail); + +Truncate Quick Example +-------------------------- + + function win(writer) { + writer.truncate(10); + }; + + var fail = function(evt) { + console.log(error.code); + }; + + entry.createWriter(win, fail); + +Write Quick Example +------------------- + + function win(writer) { + writer.onwrite = function(evt) { + console.log("write success"); + }; + writer.write("some sample text"); + }; + + var fail = function(evt) { + console.log(error.code); + }; + + entry.createWriter(win, fail); + +Append Quick Example +-------------------- + + function win(writer) { + writer.onwrite = function(evt) { + console.log("write success"); + }; + writer.seek(writer.length); + writer.write("appended text"); + }; + + var fail = function(evt) { + console.log(error.code); + }; + + entry.createWriter(win, fail); + +Abort Quick Example +------------------- + + function win(writer) { + writer.onwrite = function(evt) { + console.log("write success"); + }; + writer.write("some sample text"); + writer.abort(); + }; + + var fail = function(evt) { + console.log(error.code); + }; + + entry.createWriter(win, fail); + +Full Example +------------ + + + + FileWriter Example + + + + + +

Example

+

Write File

+ + http://git-wip-us.apache.org/repos/asf/cordova-docs/blob/40331cf8/docs/en/2.8.0rc1/edge/cordova/file/flags/flags.md ---------------------------------------------------------------------- diff --git a/docs/en/2.8.0rc1/edge/cordova/file/flags/flags.md b/docs/en/2.8.0rc1/edge/cordova/file/flags/flags.md new file mode 100644 index 0000000..fe7e224 --- /dev/null +++ b/docs/en/2.8.0rc1/edge/cordova/file/flags/flags.md @@ -0,0 +1,47 @@ +--- +license: Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--- + +Flags +===== + +This object is used to supply arguments to the `DirectoryEntry` __getFile__ and __getDirectory__ methods, which look up or create files and directories, respectively. + +Properties +---------- + +- __create:__ Used to indicate that the file or directory should be created, if it does not exist. _(boolean)_ +- __exclusive:__ By itself, exclusive has no effect. Used with create, it causes the file or directory creation to fail if the target path already exists. _(boolean)_ + +Supported Platforms +------------------- + +- Android +- BlackBerry WebWorks (OS 5.0 and higher) +- iOS +- Windows Phone 7 and 8 +- Windows 8 + +Quick Example +------------- + + // Get the data directory, creating it if it doesn't exist. + dataDir = fileSystem.root.getDirectory("data", {create: true}); + + // Create the lock file, if and only if it doesn't exist. + lockFile = dataDir.getFile("lockfile.txt", {create: true, exclusive: true});