我无法打开我的Android手机上的文件系统从API本地文件 [英] I can't open local files from Filesystem API on my Android phone
问题描述
我做了一个HTML 5应用程序下载我的服务器上的PDF文件,并在浏览器沙盒系统写入它。结果
当我去与文件系统:myServerUrl /执着,我看到正确的大小我的PDF文件。我点击它,并有一个开始下载通知,但约一秒钟后,我得到一个下载错误(原因404,当我考虑了Android日志)。结果
我试着用下载。但我有同样的错误。结果
请注意,这是我的电脑上工作正常,当我尝试用一个形象,我可以直接显示它(只需点击文件名),但不能下载它。结果
我找不到任何信息的任何地方,我失去的东西吗?
I have made an HTML 5 application that downloads a pdf file on my server, and writes it in the browser sandbox system.
When I go to filesystem:myServerUrl/persistent, I see my pdf file with the correct size. I click on it, and there is a "download started" notification, but about one second later, I get a download error (Reason 404 when I look into the Android logs).
I tried with a Download. But I have the same error.
Note that it is working fine on my computer, and when I try with an image, I can display it directly (just clicking on the file name), but cannot download it.
I can't find any piece of information anywhere, am I missing something ?
我如何下载我的文件:
function fetchResource() {
var xhr = new XMLHttpRequest();
xhr.open("GET", resourceURL, true);
xhr.responseType = "arraybuffer";
xhr.onload = function(e) {
console.log("xhr responded");
if (this.status == 200) {
console.log("status 200");
writeFile(this.response);
}
}
xhr.send();
console.log("xhr sent");
}
我怎么写我的文件:
How I write my file :
function writeFile(content){
console.log("writeFile");
fs1.root.getFile('test2.pdf', {create: true}, function(fileEntry) {
// Create a FileWriter object for our FileEntry (log.txt).
fileEntry.createWriter(function(fileWriter) {
fileWriter.onwriteend = function(e) {
console.log('Write completed.');
alert("completed");
};
fileWriter.onerror = function(e) {
console.log('Write failed: ' + e.toString());
alert("erreur: "+e.toString());
};
var blob = new Blob([content]);
fileWriter.write(blob);
}, errorHandler);
});
}
更新:英文确切的错误信息是结果<无题>结果
结果
下载失败
此外,当我一个展示地方形象,和我长单击它,选择保存图像将被禁用。难道是intented?为什么呢?
Update: the exact error message in English is
<Untitled>
Download unsuccessful
Also, when I display a local image, and I long-click it, the option "Save Image" is disabled. Could it be intented? Why?
推荐答案
我刚刚测试过此上稳定,Beta版。它那种工作。
I have just tested this on Stable, Beta. And it kind of works.
稳定(27)具有一个问题,即它不能下载的客户端生成的文件。例如,如果你使用一个[下载]属性,你会看到,它开辟了下载,但只是坐在那里无所事事。
Stable (27) has a problem where it can't download client generated files. For example if you use the a[download] attribute you will see that it opens up the downloader but just sits there doing nothing.
在测试版(28)一切正常,所以我希望你的PDF也保存。
In the Beta (28) everything works as expected, so I would expect your pdf to also save.
我简化您的code在这里: http://jsbin.com/opavet/latest 它适用于在测试两个环节。但只有后来稳定。
I simplified your code here: http://jsbin.com/opavet/latest which works for both links on Beta. But only the later on stable.
这篇关于我无法打开我的Android手机上的文件系统从API本地文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!