Flash Media Server |
|||
| Server-Side ActionScript Language Reference > Server-Side ActionScript Language Reference > File class | |||
Flash Media Server 2.
The File class lets applications write to the server's file system. This is useful for storing information without using a database server, creating log files for debugging, or tracking usage. Also, a directory listing is useful for building a content list of streams or shared objects without using Flash Remoting.
The File object allows access to the server file system. To protect against any misuse, Flash Media Server allows access to files within a sandbox specified for the virtual host where the application instance is running.
|
TIP |
|
A sandbox is a security feature that determines how an application can interact with the local file system, the network, or both the local file system and network at the same time. Restricting how a file can interact with the local file system, or the network helps keep your computer and files safe. |
The server administrator can set up the sandbox for all applications within a virtual host and can provide additional control to individual applications, if required. The following rules are enforced by the server:
A virtual directory mapping can be set up to access files outside the application directory.
Access is denied if a path contains a backslash (\) or if a dot (.) or two dots (..) is the only string component found between path separators.
For example, if a path using the slash (/) is used to create a File object, the application folder is mapped.
This is done by specifying a FileObject tag within the JSEngine section in the Application.xml file, as shown in the following example:
<JSEngine>
<FileObject>
<VirtualDirectory>/videos;C:\myvideos</VirtualDirectory>
<VirtualDirectory>/fcsapps;C:\Program Files\fcs\applications</
VirtualDirectory>
</FileObject>
</JSEngine>
This example specifies two additional directory mappings in addition to the default application directory. Any path specified with /videos/xyz/vacation.flv maps to c:/myvideos/xyz/vaction.flv. Similarly, /fcapps/conference maps to c:/Program Files/fcs/applications/conference. Any path that does not match this mapping resolves to the default application folder. For example, if c:/myapps/filetest is the application directory, then /streams/hello.flv maps to c:/myapps/filetest/streams/hello.flv.
The File object invokes the Application.onStatus event handler to report errors when the following File class methods fail:
|
Method |
Description |
|---|---|
|
Closes the file. |
|
|
Copies a file to a different location or to the same location with a different filename. |
|
|
Returns a Boolean value indicating whether the file pointer is at the end of file ( |
|
|
Flushes the output buffers of a file. |
|
|
If the file is a directory, returns an array with an element for each file in the directory. |
|
|
Attempts to create a directory in the file directory. |
|
|
Opens a file so that you can read from it or write to it. |
|
|
Reads the specified number of characters from a file and returns a string. |
|
|
Reads the file and returns an array with an element for each line of the file. |
|
|
Reads the next byte from the file and returns the numeric value of the next byte, or -1 if the operation fails. |
|
|
Reads the next line from the file and returns it as a string. |
|
|
Removes the file or directory pointed to by the File object. |
|
|
Moves or renames a file. |
|
|
Writes data to a file. |
|
|
Takes an array as a parameter and calls the File.writeln() method on each element in the array. |
|
|
Writes a byte to a file. |
|
|
Writes data to a file and adds a platform-dependent end-of-line character after outputting the last parameter. |
|
|
Skips a specified number of bytes and returns the new file position. |
|
|
Returns a string that indicates the name of the File object. |
|
Property |
Description |
|---|---|
|
Read-only; a Boolean value indicating whether a file was open for appending ( |
|
|
Read-only; a Boolean value indicating whether a file can be read ( |
|
|
Read-only; a Boolean value indicating whether a file was opened with the replace flag enabled ( |
|
|
Read-only; a Boolean value indicating whether you can write to a file ( |
|
|
Read-only; a Date object containing the time the file was created. |
|
|
Read-only; a Boolean value indicating whether the file or directory exists ( |
|
|
Read-only; a Boolean value indicating whether the file is a directory ( |
|
|
Read-only; a Boolean value indicating whether the file is a regular data file ( |
|
|
Read-only; a Boolean value indicating whether the file has been successfully opened and is still open ( |
|
|
Read-only; a Date object containing the time the file was last modified. |
|
|
Read-only; for a directory, the number of files in the directory, not counting the current directory and parent directory entries; for a file, the number of bytes in the file. |
|
|
Read-only; the mode of an open file. |
|
|
Read-only; a string indicating the name of the file. |
|
|
The current offset in the file. |
|
|
Read-only; a string specifying the type of data or encoding used when a file is opened. |
Flash Media Server 2.
fileObject = new File(name)
name Specifies the name of the file or directory. The name can contain only UTF-8 encoded characters; high byte values can be encoded using the URI character- encoding scheme. The specified name is mapped to a system path using the mappings specified in the Application.xml file. If the path is invalid, the name property of the object is set to an empty string, and no file operation can be performed.
A File object if successful; otherwise, null.
Constructor; to create an instance of the File class, use the standard syntax for object creation.
The following code creates an instance of the File class:
var errorLog = new File("/logs/error.txt");