【发布时间】:2017-11-13 18:34:02
【问题描述】:
最近我在实际工作中一直在研究这个主题,所有研究都集中在这个 availableBytes 函数上,您可以在下面看到:
function onInitFs(fs) {
var appDirectory = fs.root;
window.alert("Directorio de trabajo: " + appDirectory.toURL());
availableBytes(function (free_bytes) {
console.log("Interal free space(root + internal): " + (free_bytes / (1024 * 1024 * 1024)).toFixed(0) + "GB");
});
}
//Function used to know available space in internal storage
function availableBytes(callback, start, end) {
callback = callback == null ? function () {} : callback
start = start == null ? 0 : start
end = end == null ? 1 * 1024 * 1024 * 1024 * 1024 : end
//starting with 1 TB
limit = 1024 // precision of 1kb
start_temp = start
end_temp = end
callback_temp = callback
if (end - start < limit)
callback(start)
else {
window.requestFileSystem(LocalFileSystem.PERSISTENT, parseInt(end_temp - ((end_temp - start_temp) / 2)), function (fileSystem) {
setTimeout(function () {
availableBytes(callback_temp, parseInt(parseInt(end_temp - ((end_temp - start_temp) / 2))), end_temp)
}, 0)
}, function () {
setTimeout(function () {
availableBytes(callback_temp, start_temp, parseInt(end_temp - ((end_temp - start_temp) / 2)))
}, 0)
})
}
}
如您所见,我们可以很容易地知道内部存储空间大小,但根目录(即我存储下载的视频和音乐的位置,客户端不会轻易访问的位置)不能被“询问”,所以...有人知道这样做的正确方法吗?
【问题讨论】:
-
不知道它是否有帮助,但是当您尝试保存文件并且没有剩余空间时,请求将失败,错误代码为 10 (QUOTA EXCEEDED_ERR)
标签: javascript android ios html cordova