1.1.0 • Published 9 years ago
wxapp-file_reqst v1.1.0
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 urlStringtruethe url to download resources. nameStringfalserename the file.(default is download name) collisionStringfalse'both'or'older'or'newer'.(default is'newer')csnameStringfalsewhen collision is set to 'both', file will be renamed to csname.headerObjectfalserequest header. successFunctionfalsethe callback when successfully saved. failFunctionfalsethe callback when save failed. completeFunctionfalsethe 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.