本帖最后由 破晓 于 2015-2-2 16:51 编辑
ANEFileSyncIt lets you to: - serve static web pages
- upload files to the device via POST
- actions to rename, delete, create dirs and list dir contents
- list directory contents
UsageThere is a known bug in the simulator that prevents to upload files,so the application quits unexpectedly. Avaliable Class Methods
Returns if the native extension is supported or not
Disposes the extension- getDirectoryListingEnabled() : Boolean;
复制代码
Returns the state of the - getDocumentRoot() : File;
复制代码
Returns the actual DocumentRoot File- getEnabledActions() : String;
复制代码
Returns a comma separated string of the active actions
Returns the current device ip.When no connection is avalible it will return 0.0.0.0Also when running in simulator it will return 0.0.0.0 but you can access it locating your current machine ip- getModificationDateFormat() : String;
复制代码
Returns the current date format.
Returns the current listening port
Returns the actual Upload dir- getUploadDirectoryListingEnabled() : Boolean;
复制代码
Returns true if the actual upload dir is browseable otherwise returns false- setDirectoryListingEnabled(enabled : Boolean) : void;
复制代码
When enabled, if the current directory has no index.html file shows a directory listing- setDocumentRoot(directory : File) : void;
复制代码
Sets the current webserver root directory- setEnabledActions(actions : String) : void;
复制代码
Comma separated string to set the avaliable server actions.By default all avaliable actions are enabled.Avaliable actions are:* createDir* delete* rename* listDir* uploade.g: setEnabledActions('createDir,delete');- setModificationDateFormat(format : String) : void;
复制代码
Sets the current modification date format.The default format is yyyy/MM/dd HH:mm- setPort(port : uint) : void;
复制代码
Sets the current listening port- setUploadDir(uploadDir : File) : void;
复制代码
Sets the current webserver upload directoryThe upload dir can be inside or outside the webserver root directory- setUploadDirectoryListingEnabled(enabled : Boolean) : void;
复制代码
Lets you hide/show the upload directory when it is inside the webserver root and directory listing is enabled
Starts the server.Returns true on success otherwise returns false
Stops the server
Avaliable Class EventsANEFileSyncEvent.FILE_UPLOADED Dispatched when a file upload is completed
event.data.filename
contains the name of the uploaded file
event.data.path
contains the native path to the uploaded fileANEFileSyncEvent.FILE_DELETED Dispatched when a file has been deleted
event.data.result
contains true if the file has been correctly deleted otherwise contains false
event.data.path
contains the native path to the deleted fileANEFileSyncEvent.FILE_RENAMED Dispatched when a file has been renamed
event.data.from
contains the original renamed file path
event.data.to
contains the final renamed file path
event.data.result
contains true if the file has been correctly renamed otherwise contains falseANEFileSyncEvent.DIRECTORY_CREATED Dispatched when a directory has been created
event.data.result
contains true if the directory has been correctly created otherwise contains false
event.data.path
contains the native path to the created directoryANEFileSyncEvent.SERVER_STARTED Dispatched when the server starts
event.data.ip
contains the server current ip. ( 0.0.0.0 in Simulator )
event.data.port
contains the server current portANEFileSyncEvent.SERVER_STOPED Dispatched when the server stops Minimal contens of DocumentRoot directory
You must include a directory named ___templates___. Inside this directory you must provide a file named 404.html that will show generic server errors. Also if you set DirectoryListingEnabled you must provide a file named dir.html that will be used to show the default Directory Listing dir.html templating
dir.html uses mustache templating system to render his contents. The current avaliable properties passed to the template are:
- {{parent}} The parent dir path
- {{files}} Array containing the current directory files
- Use this minimal template to access each file properties:
- {{#files}}
- {{type}} // can be file or dir
- {{path}} // full file path
- {{name}} // file name
- {{size}} // file size in bytes
- {{modification}} // modification date
- {{/files}}
复制代码Basic Document root example is located at BasicDocumentRoot directoryAlso you can find a working example of DocumentRoot inside the provided example/bundle dir Client side javascript methods to interact with the serverA little javascript library to interact with the server actions.To use it include the IOSFileSync.js to your page.
All the paths used must be relative to the DocumentsRoot or UploadDir
The library uses the promise approach to interact with IOSFileSync methods, so you can use it as: - IOSFileSync.methodXXX().then( success, fail, progress /* only 4 upload */ );
复制代码 Avaliable javascript methodsIOSFileSync.rename- IOSFileSync.rename( from , to ).then( success, fail );
复制代码 IOSFileSync.deleteFile
- IOSFileSync.deleteFile( file ).then( success, fail );
复制代码 IOSFileSync.createDir
- IOSFileSync.createDir( dir ).then( success, fail );
复制代码 IOSFileSync.listDir
- var success = function( data )
- {
- // data will contain an array of file objects
- /*
- [
- {
- path:'full file path',
- name:'filename',
- isDir:'true if file is a directory',
- size:'the file size in bytes'
- },...
- ]
- */
- }
- var fail = function( error )
- {
- // error will contain the error description
- // posible errors are 'emptydir' 'notfound' 'serverNotFound'
- }
- IOSFileSync.listDir( dir ).then( success, fail );
复制代码 IOSFileSync.upload
- var progress = function( percentage )
- {
- console.log( 'Uploaded '+percentage+'%');
- }
- IOSFileSync.upload(
- file /* File object */,
- path /* you can provide a relative path from the default upload path */
- ).then(
- success,
- fail,
- progresss
- );
复制代码 Basic Example
Inside the example folder you can find a minimal example that lets you upload an image to the server. The image will be shown at the device, after that you can click on "Get upload dir contents" to get a list of the files inside the upload dir. License
相关链接:
https://github.com/xperiments/ANEFileSyncInterface
|