webkitStorageInfo.queryUsageAndQuota()用于查找使用我认为的HTML5文件系统API存储在文件系统中的文件的使用情况统计信息.任何人都可以给我提供可以在提供给该函数的回调中获得的详细信息.
window.webkitStorageInfo.queryUsageAndQuota(webkitStorageInfo.PERSISTENT, function() {
//what all details can be obtained in this function as its arguments?
})
Run Code Online (Sandbox Code Playgroud) html5 google-chrome google-chrome-extension fileapi html5-filesystem
所以我正在尝试创建一个文件管理器Web应用程序.现在,用户可以在屏幕上删除文件,我可以读取它们,包括删除的目录中的所有文件.但是,我不知道脚本何时完成读取文件.
一些代码:
第一个函数处理'drop'事件,并循环遍历每个文件并将其发送到另一个将读取其内容的函数.
function readDrop( evt )
{
for( var i = 0; i < evt.dataTransfer.files.length; i++)
{
var entry = evt.dataTransfer.items[i].webkitGetAsEntry();
if(entry)
readContents(entry, "");
}
//Do stuff after all files and directories have been read.
}
Run Code Online (Sandbox Code Playgroud)
此函数是递归FileEntry读取器.如果是文件,我会读取FileEntry.如果它是一个目录,它将循环遍历内容并通过该函数传递它.
function readContents(entry, path)
{
if( entry.isFile )
{
readFileData( entry, path, function(fileData)
{
_MyFiles.push( fileData );
});
}
else if( entry.isDirectory )
{
var directoryReader = entry.createReader();
var path = path + entry.name;
directoryReader.readEntries(function(results)
{
for( var j = 0; j < …Run Code Online (Sandbox Code Playgroud) 我可以/home/Users/user1/使用名称保存自定义位置()中的文件file1.txt.
我有这个代码:
chrome.fileSystem.chooseEntry({type:'openDirectory'}, function(entry) {
chrome.fileSystem.getWritableEntry(entry, function(entry) {
entry.getFile('file1.txt', {create:true}, function(entry) {
entry.createWriter(function(writer) {
writer.write(new Blob(['Lorem'], {type: 'text/plain'}));
});
});
});
});
Run Code Online (Sandbox Code Playgroud)
使用此代码,我得到提示,所以我需要选择目录,但我想没有它,我想在设置中声明目录位置.
对此有何解决方案?
编辑
根据@Xan接受的回答:
// set location
$('#location_field').on('click', function(){
chrome.fileSystem.chooseEntry({type:'openDirectory'}, function(entry) {
chrome.storage.sync.set({'print_location': chrome.fileSystem.retainEntry(entry)});
});
});
// get location
var print_location = null;
chrome.storage.sync.get({
print_location: null
}, function(items){
chrome.fileSystem.restoreEntry(items.print_location, function(entry){
print_location = entry;
});
});
// save file
chrome.fileSystem.getWritableEntry(print_location, function(entry) {
entry.getFile('file1.txt', {create:true}, function(entry) {
entry.createWriter(function(writer) {
writer.write(new Blob(['Lorem'], {type: 'text/plain'}));
});
});
});
Run Code Online (Sandbox Code Playgroud) html5 google-chrome google-chrome-extension html5-filesystem google-chrome-app
我想允许用户拖动和上传目录和文件。
我知道我可以创造
<input type="file" multiple />
<!-- for files/multiple files upload-->
Run Code Online (Sandbox Code Playgroud)
和
<input type="file" directory mozDirectory webkitDirectory />
<!-- for directory uploads -->
Run Code Online (Sandbox Code Playgroud)
我尝试检测用户拖动项目时是否是目录或文件,并根据该情况设置目录属性,但事实证明 javascript 不允许您检查它。
我还在很多网站上看到,用户可以将文件和目录甚至多个目录拖到一起。
我怎样才能做到这一点?
有一个文件系统 API,但现在显示为已弃用: https:
//developer.mozilla.org/en-US/docs/Web/API/Window/requestFileSystem
现在还有另一个文件系统访问 API:
https://developer.mozilla.org/en-US/docs/Web/API/File_System_Access_API
旧 API 发生了什么情况以及为何停止使用?新的文件系统访问 API 在所有常见浏览器中是否应该稳定?
我正在测试一些新的 JS 文件系统功能,即在本地文件系统中创建一个空文本文件。我正在从本地路径 (file:///) 运行 HTML 和 JS 文件。为此,我使用--allow-file-access-from-filesCLI 的标志启动了 Google Chrome。文件系统请求是持久的(并且有效)。
我阅读了有关文件系统的不同帖子,复制并修改了教程中的一些代码;当我启动 HTML 文件时,我的自定义成功/失败消息将输出在控制台中;
这是结果:
Opened file system:/ // this is the root path of the JS Filesystem.
/wtf.txt // this is the name and path of the text file I created+ it's a success
Run Code Online (Sandbox Code Playgroud)
但是,当我查看目录(系统和应用程序根目录)时,没有具有我分配给它的名称的 .txt 文件。我怎么知道 Javascript 到底在哪里写了这个文件?在什么“根”中(因为“根”不能被分配)?文件系统是“沙箱”是什么意思?我无法访问本地驱动器上的(虚拟?)内容,而只能使用 JS?如果是这种情况,有没有办法提示用户保存文件?
预先感谢您的回答
如何在 Angular 4 应用程序中使用 TypeScript 中的 FileSystem API?
我添加@types/filesystem到devDependencies,但我仍然收到编译错误,例如
“窗口”类型上不存在属性“resolveLocalFileSystemURL”。
找不到名称“文件错误”。
找不到名称“FileEntry”。
我tsconfig.json的和 angular-cli 生成的几乎一样,我只是添加"node_modules/typed-cordova-plugin-purchase到typeRoots:
{
"compileOnSave": false,
"compilerOptions": {
"outDir": "./dist/out-tsc",
"baseUrl": "src",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types",
"node_modules/typed-cordova-plugin-purchase"
],
"lib": [
"es2016",
"dom"
]
}
}
Run Code Online (Sandbox Code Playgroud)
我应该导入任何东西吗?有没有在 Typescript 中使用 FileSystem 的例子?
javascript ×4
filesystems ×2
html5 ×2
angular ×1
file-io ×1
fileapi ×1
html ×1
typescript ×1
web ×1