wxapp-file_reqst
v1.1.0
Published
A module to manage files and offer a request queue in wxapp.
Downloads
10
Readme
wxapp-file-reqst
A module to manage files and offer a request queue in wxapp.
Import
var file_reqst = require('/path/to/file_reqst.js');Usage
getRemainSpace()This will return the remaining space of local file storage.
Page({ ... someMethod: function(){ ... remainingSpace = file_reqst.getRemainSpace(); ... } })
downloadAndSave(obj)Required object format:
| key | type | required | value | | ----------- | ---------- | -------- | ---------------------------------------- | |
url|String|true| the url to download resources. | |name|String|false| rename the file.(default is download name) | |collision|String|false|'both'or'older'or'newer'.(default is'newer') | |csname|String|false| when collision is set to'both', file will be renamed to csname. | |header|Object|false| request header. | |success|Function|false| the callback when successfully saved. | |fail|Function|false| the callback when save failed. | |complete|Function|false| the callback when save completed. |P.S.
csnameis required when collision is set to'both'.... file_reqst.downloadAndSave({ url: 'https://example.com/file/path', name: 'rename.ext' }); ...getAllFiles()This will return all the files managed by file_reqst.js.
getFile(name, callback)This will return the file path corresponding to the name. And the callback will receive an object like the following one:
{ filePath: 'path/to/your/file', createTime: 1490870527394, size: 233 }P.S. An Exception will be thrown when file doesn't exist.
removeFile(name, callback)The callback will receive an object like the following one:
{ message: 'fail', info: {something provided by wxapp} } { message: 'ok', info: {something provided by wxapp} }clearFile(callback)The callback will receive an object like
removeFilereceived.
