File plugin

From KuneriLite wiki

Contents

Introduction

Flash Lite accesses File plugin via loadVariables with 5 basic commands.

Interface

loadVariables("http://127.0.0.1:<Port>/<Key>/file?klCommand=<Command>&<Arguments>,
"<TargetMc>", "<Method>");
General Parameters
<Port> Specific port KuneriLite is listening commands from (default 1001)
<Key> Unique key for your KuneriLite license (default Basic)
<Command> Name of the command to be called.
<Arguments> Required arguments for commands. Each command may have different arguments with various parameter values.
<TargetMC> Flash Lite movie clip that will receive the response back.
<Method> Use "POST"-method when writing large amount(>800 bytes) of data, otherwise leave this field empty.

Status of a command can be controlled via klError and klEnd variables. klError returns the response message from KuneriLite server application and klEnd value indicates that conversation is finalized and all data is received. For meaning of klError values, please refer to "Error Values" section below

loadVariables-call syntax is different for POST method.

Commands

Create

Creates a file at a specified path on local device.

Returns

Returns 0 to klError if successful, or an error code if there is any problem creating file.

Arguments

klPath Path for the file to be created. If folder of file is not given, file is looked first from application installation folder. Relative paths are also supported (relative to app. install folder). For instance: 'files\\main.txt' (same as 'c:\\data\\my app\\files\\main.txt')

Example

loadVariables("http://127.0.0.1:1001/Basic/file?klCommand=create&klPath=\\NewFile.txt", "");

Delete

Deletes a file from a specified path.

Returns

Returns 0 to klError if successful, or an error code if there is any problem deleting file.

Arguments

klPath Path of the file to be deleted

Example

loadVariables("http://127.0.0.1:1001/Basic/file?klCommand=delete&klPath=\\NewFile.txt", "");

Write

Writes data to a file specified.

Returns

Returns 0 to klError if successful, or an error code if there is any problem writing to the file.

Arguments

klPath Path of the file to be written
klData Data to be written

Example


loadVariables("http://127.0.0.1:1001/Basic/file?klCommand=write&klPath=\\NewFile.txt&
klData=This is the first data", "");

This writes string This%20is%20encoded%20string to the file. (klUrlDecodeOff=1 disables default URL-decoding in KuneriLite for this request, so that %20 won't turn into space character):

loadVariables("http://127.0.0.1:1001/Basic/file?klCommand=write&klPath=\\NewFile.txt& klUrlDecodeOff=1&klData=This%20is%20encoded%20string", "");

Append

Appends data to a specified file.

Returns

Returns 0 to klError if successful, or an error code if there is any problem appending to the file.

Arguments

klPath Path of the file to append
klData Data to be appended

Example

loadVariables("http://127.0.0.1:1001/Basic/file?klCommand=append&klPath=\\NewFile.txt&klData=I append this text", "");

Clear

Clears all data in a specified file.

Returns

Returns 0 to klError if successful, or an error code if there is any problem clearing the file.

Arguments

klPath Path of the file to be cleared

Example

loadVariables("http://127.0.0.1:1001/Basic/file?klCommand=clear&klPath=\\NewFile.txt", "");

Rename

Renames given file.

Returns

Returns 0 to klError if successful, or an error code if there is any problem renaming the file.

Arguments

klPath Path of the file to be renamed
klTargetFile New name for the file

Note: Both klPath and klTargetFile should have also folder specified. If not, application installation path is assumed.

Example

loadVariables("http://127.0.0.1:1001/Basic/file?klCommand=rename&klPath=\data\myfile1.txt&klTargetFile=\data\myfile2.txt", "");

Exist

Checks if specified file exists.

Returns

Returns 0 to klError if successful and if file exist, -1 if file does not exist or any else error value if there was problem accessing the file.

Arguments

klPath Path of the file to check

Example

loadVariables("http://127.0.0.1:1001/Basic/file?klCommand=exist&klPath=\\NewFile.txt", "");

Dir

Lists folders and files of the specified path.

Returns

klError Error code (0 if successful)
klDirCount (When klArgs=/s IS NOT given) Number of folders in the specified path
klDir[1..X] (When klArgs=/s IS NOT given) Name of the directory where X is equal to klDirCount

(e.g. klDir1=Images&klDir2=Videos&)

klFileCount Number of files in the specified path
klFile[1..Y] Name of the file where Y is equal to klFileCount (e.g. klFile1=Data.txt&klFile2=image.jpg&)

Arguments

klPath Path, where the command will be executed. If klPath is not given, application installation folder is used by default.
klArgs Special optional arguments:

/s : Returns all files with path, from subfolders relative to klPath in form: klFile[1..Y]=subfolder\subfolder2\file.ext&

(e.g klFile1=\data\images\image.jpg&klFile2=\data\videos\video.3gp&)


Example

loadVariables("http://127.0.0.1:1001/Basic/file?klCommand=dir&klPath=\\&klArgs=/s", "");

Mkdir

Creates a folder in specified path.

Returns

Returns 0 to klError if successful, or an error code if there is any problem creating the directory.

Arguments

klPath Path of the directory to be created.

Example

loadVariables("http://127.0.0.1:1001/Basic/file?klCommand=mkdir&klPath=\\MyDir", "");

Rmdir

Removes a folder or folder structure, except protected ones. Folder can be empty or have files and folders.

Returns

Returns 0 to klError if successful, or an error code if there is any problem removing the directory.

Arguments

klPath Path of the directory to be removed.

Unzip

Downloading files in zip format is efficient way to create large file structures into phone. Unzip command simply extracts single zip-file into specified target directory.

Returns

Returns 0 to klError if successful, or an error code if there is any problem in extracting.

Arguments

klFile Source zip file.
klPath Path to the target directory where to extract files.
klArgs=/p Prompts to overwrite files, by default all files are written over.


Example

loadVariables("http://127.0.0.1:1001/Basic/file?klCommand=unzip&klFile=package.zip&klPath=MyDir\", 
"");

isMCused

Checks if currently running application is installed to memory card.

Returns

Returns 1 to klValue if installed, 0 if not or an error code if there is any problem.

Error values

Common error statuses are mentioned below.

0 Success
-1 File or path not found / KuneriLite components are missing.
-5 Plugin name, command or type in URL is not supported / restricted command
-6 Given data is out of range
-11 File already exists.
-12 Given path is not found
-14 File is locked
-28 Given URL is malformed
Personal tools