我正在尝试Firefox,IE 9,Chrome和Opera下面的代码,但是onInitFs(fs)函数没有被调用.如果我在window.requestFileSystem中添加'()'到onInitFs(window.PERSISTENT,1024*1024,onInitFs,errorHandler)该函数被调用但fs为null?有谁知道如何解决这个问题?我试试Windows 7.我非常感谢你的帮助.
<!DOCTYPE HTML>
`<html>
<head>
<script>
function errorHandler(e){
alert("errorrrr");
}
function onInitFs(fs){
alert("onInitFs");
}
function readClick(){
if (window.webkitRequestFileSystem) {
window.webkitRequestFileSystem(window.PERSISTENT, 1024*1024,onInitFs,errorHandler);
}
else {
window.requestFileSystem(window.PERSISTENT, 1024*1024, onInitFs, errorHandler);
}
alert("read finishsssss");
}
</script>
</head>
<body>
<input type="button" value="Read dir" onclick="readClick()">
<ul id="filelist"></ul>
</body>
</html>
Run Code Online (Sandbox Code Playgroud) 从MEGA服务下载文件时,将显示一个显示下载进度条的网页.栏达到100%后,您的浏览器将通知用户将文件保存到选定的文件夹中.我知道Mega使用HTML5 FileSystem API来做到这一点(下载像mega.co.nz这样的文件).但是,我不知道文件何时完全下载到沙盒目录中,浏览器如何通知用户有关下载的信息?你能回答我的问题吗?提前致谢.
我正在使用HTML5文件API将文件上传到我的Web应用程序.
我的网页上有一个输入元素,我用它来读取文件和调用上传功能
<input type="file">
$('input[type="file"]').on("change",function(e){
console.log(this.files);
// upload each file in this.files
});
Run Code Online (Sandbox Code Playgroud)
这适用于os上的本机文件.我想现在上传远程文件,例如example.com/blah/file1.jpg我的问题是如何使用File API读取此文件?有办法吗?
我只是通过Cordova源代码来试图找出一些东西,目前有六种替代方法/属性来访问文件的路径.
目前(使用iOS运行),有:
// Properties
file.fullPath; // file:///full/path/syntax/file
file.nativeURL; // file:///full/path/syntax/file
// Method(s)
file.toInternalURL(); // formats the file.fullPath into a cdvfile://localhost/persisten/file.
file.toURL(); // if file.nativeURL is set, uses file.nativeURL, otherwise use file.toInternalURL() or file.fullPath.
// Deprecated method(s)
file.toURI(); // deprecated - calls file.toURL();
file.toNativeURL() // deprecated - calls file.toURL();
Run Code Online (Sandbox Code Playgroud)
我理解两个都被弃用 - 这两个都指向file.toURL()- 所以我可以忽略它们并专注于四种方法.
但是file.fullPath和file.nativeURL它们之间有什么区别- 它们完全相同?它们都是文件对象的属性 - 都可以公开访问.
据我所知,file.toURL()使用这两种方法 - 首先file.nativeURL如果不是那样,那么file.toInternalURL()或者那么失败file.fullPath.
最后,file.toNativeURL()返回一个cdvfile://格式化的位置. …
如何完全清空(或删除文件系统中的所有文件)?
没有像localStorage(localStorage.clear())那样的1行解决方案吗?或者我错过了一些非常非常明显的东西?
显然,我不是很清楚.我指的是HTML5 Filesystem API.http://www.html5rocks.com/en/tutorials/file/filesystem/
我试图找出浏览器是否有能力选择文件夹,而不仅仅是多个文件.目前的Chrome支持此功能(例如:http://html5-demos.appspot.com/static/html5storage/demos/upload_directory/index.html).
显然,它<input type="file" />具有webkitdirectory属性时可以在Chrome中使用.但是,我如何测试浏览器是否实际上能够选择文件夹并迭代文件?
我有以下代码:
chrome.runtime.getPackageDirectoryEntry(function(directoryEntry)
{
directoryEntry.getFile("files/test.txt", {create: true, exclusive: false}, function(fileEntry)
{
console.log(fileEntry);
},
function(error)
{
console.log(error);
});
});
Run Code Online (Sandbox Code Playgroud)
如果文件不存在且create为true,则会It was determined that certain files are unsafe for access within a Web application, or that too many calls are being made on file resources.出错.但如果确实存在且create为false,则可以访问该文件.
我究竟做错了什么?
我无法使cordova文件系统工作.我有一个具有以下依赖项的项目:
com.ionic.keyboard 1.0.3 "Keyboard"
org.apache.cordova.console 0.2.12 "Console"
org.apache.cordova.device 0.2.13 "Device"
org.apache.cordova.file 1.3.2 "File"
org.apache.cordova.file-transfer 0.4.8 "File Transfer"
Run Code Online (Sandbox Code Playgroud)
在app.js我定义对控制器模块的依赖:
angular.module('starter', ['ionic', 'controllers']);
Run Code Online (Sandbox Code Playgroud)
控制器代码基本上是这样的:
angular.module('controllers', [])
.controller('GalleryCtrl', function ($scope) {
function success() {...}
function error() {...}
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, success, error);
}
}
Run Code Online (Sandbox Code Playgroud)
然后我得到的是:
LocalFileSystem is not defined
Run Code Online (Sandbox Code Playgroud)
此外,requestFileSystem未定义.这种行为可能是什么原因?
我使用的是cordova 4.1.2和离子1.3.1.
编辑:这是相应的HTML标记:
<body ng-app="starter" ng-controller="GalleryCtrl">
<ion-nav-view>
<ion-slide-box id="slideBox">
<ion-slide ng-repeat="..."> <!-- details omitted -->
</ion-slide>
</ion-slide-box>
</ion-nav-view>
</body>
Run Code Online (Sandbox Code Playgroud) 我在一个网站上有一个简单的图像上传器和一个javascript函数,它使用FileReader并将图像转换为base64,以便用户显示它而无需将其上传到实际的服务器.
function generateThumb(file) {
var fileReader = new FileReader();
fileReader.readAsDataURL(file);
fileReader.onload = function (e) {
// Converts the image to base64
file.dataUrl = e.target.result;
};
}
Run Code Online (Sandbox Code Playgroud)
现在我正在尝试使用Mocha和编写此方法的测试Chai.我的想法是,我想检查是否file.dataUrl已成功创建并且它是base64.所以我想在测试环境中以某种方式模拟本地文件(不知道如何做到这一点).或者我根本不应该测试这个并假设这是有效的?
我可以使用文件系统访问 API ( https://web.dev/file-system-access/ ) 在网站内创建类似文件资源管理器的东西 (react)。
我计划制作一个简单的在线文件资源管理器,让您浏览打开一个文件夹,然后让您浏览该文件夹、播放视频和 MP3。
(我知道几年前这是不可能的,因为 js 不可能访问本地存储中的任何内容,我只是想知道是否有任何更改。如果文件系统访问 API 不是可行的方法,您能否建议一些更好的方法来从文件夹中读取批量本地文件。)
javascript filesystem-access html5-filesystem reactjs file-system-access-api
html5-filesystem ×10
javascript ×7
html5 ×5
cordova ×2
filereader ×2
file-upload ×1
ionic ×1
mocha.js ×1
reactjs ×1