gpt4 book ai didi

javascript - 打开失败 : EROFS (Read-only file system) android phonegap app

转载 作者:太空宇宙 更新时间:2023-11-04 11:14:53 24 4
gpt4 key购买 nike

我正在尝试将 Progress 事件与 PhoneGap 一起用于文件传输。

我的问题是每次按下下载按钮时,都会出现以下错误。

我在这个链接下找到了代码并完整复制了它:http://www.raymondcamden.com/2013/05/01/Using-the-Progress-event-in-PhoneGap-file-transfers

错误:10-23 23:55:38.407 24464-24508/? E/FileTransfer:{"target":"//download.mp3","http_status":200,"code":1,"source":"http://archive.org/download/Kansas_Joe_Memphis_Minnie-When_Levee_Breaks/Kansas_Joe_and_Memphis_Minnie- When_the_Levee_Breaks.mp3","exception":"/download.mp3: 打开失败:EROFS(只读文件系统)"} java.io.FileNotFoundException:/download.mp3: 打开失败:EROFS(只读文件系统) 在 libcore.io.IoBridge.open(IoBridge.java:409) 在 java.io.FileOutputStream.(FileOutputStream.java:88) 在 org.apache.cordova.CordovaResourceApi.openOutputStream(CordovaResourceApi.java:329) 在 org.apache.cordova.CordovaResourceApi.openOutputStream(CordovaResourceApi.java:310) 在 org.apache.cordova.filetransfer.FileTransfer$4.run(FileTransfer.java:894) 在 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 在 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 在 java.lang.Thread.run(Thread.java:841) Caused by: libcore.io.ErrnoException: open failed: EROFS (只读文件系统) 在 libcore.io.Posix.open( native 方法) 在 libcore.io.BlockGuardOs.open(BlockGuardOs.java:110) 在 libcore.io.IoBridge.open(IoBridge.java:393)在 java.io.FileOutputStream.(FileOutputStream.java:88)在 org.apache.cordova.CordovaResourceApi.openOutputStream(CordovaResourceApi.java:329)在 org.apache.cordova.CordovaResourceApi.openOutputStream(CordovaResourceApi.java:310)在 org.apache.cordova.filetransfer.FileTransfer$4.run(FileTransfer.java:894)在 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)在 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)在 java.lang.Thread.run(Thread.java:841)

index.html

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name = "format-detection" content = "telephone=no"/>
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width" />
<link rel="stylesheet" type="text/css" href="css/index.css" />
<title>FileTransfer Test</title>
</head>
<body>

<div id="content">
<p>
Kansas Joe McCoy and Memphis Minnie – "When The Levee Breaks"
</p>

<img src="img/KansasJoeAndMemphisMinnie.jpg">

<p>
<button id="startDl">Click to Download and Play</button>
</p>
</div>

<div id="status"></div>

<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/app.js"></script>
</body>
</html>

应用程序.js

document.addEventListener('deviceready', deviceready, false);

var buttomDom;
var statusDom;
var fileSystem;

function deviceready() {
console.log('dv ready');

//step one is to request a file system
window.requestFileSystem(LocalFileSystem.TEMPORARY, 0,
function(fs) {
fileSystem = fs;

buttonDom = document.querySelector('#startDl');
buttonDom.addEventListener('touchend', startDl, false);
buttonDom.removeAttribute("disabled");

statusDom = document.querySelector('#status');
}, function(e) {
alert('failed to get fs');
alert(JSON.stringify(e));
});
}

function startDl() {
buttonDom.setAttribute("disabled","disabled");

var ft = new FileTransfer();
var uri = encodeURI("http://archive.org/download/Kansas_Joe_Memphis_Minnie-When_Levee_Breaks/Kansas_Joe_and_Memphis_Minnie-When_the_Levee_Breaks.mp3");

var downloadPath = fileSystem.root.fullPath + "/download.mp3";

ft.onprogress = function(progressEvent) {
if (progressEvent.lengthComputable) {
var perc = Math.floor(progressEvent.loaded / progressEvent.total * 100);
statusDom.innerHTML = perc + "% loaded...";
} else {
if(statusDom.innerHTML == "") {
statusDom.innerHTML = "Loading";
} else {
statusDom.innerHTML += ".";
}
}
};

ft.download(uri, downloadPath,
function(entry) {
statusDom.innerHTML = "";
var media = new Media(entry.fullPath, null, function(e) { alert(JSON.stringify(e));});
media.play();

},
function(error) {
alert('Crap something went wrong...');
});


}

最佳答案

我找到了一个解决方案,我将完整路径更改为 root.toURL() 。

关于javascript - 打开失败 : EROFS (Read-only file system) android phonegap app,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33314953/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com