Reputation: 89
I'm trying to use a Progress event with PhoneGap for file transfers.
My problem is that every time when I press the download button, the errors below appear.
I found the code under this link and copied it completely: http://www.raymondcamden.com/2013/05/01/Using-the-Progress-event-in-PhoneGap-file-transfers
Error: 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: open failed: EROFS (Read-only file system)"} java.io.FileNotFoundException: /download.mp3: open failed: EROFS (Read-only file system) at libcore.io.IoBridge.open(IoBridge.java:409) at java.io.FileOutputStream.(FileOutputStream.java:88) at org.apache.cordova.CordovaResourceApi.openOutputStream(CordovaResourceApi.java:329) at org.apache.cordova.CordovaResourceApi.openOutputStream(CordovaResourceApi.java:310) at org.apache.cordova.filetransfer.FileTransfer$4.run(FileTransfer.java:894) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) at java.lang.Thread.run(Thread.java:841) Caused by: libcore.io.ErrnoException: open failed: EROFS (Read-only file system) at libcore.io.Posix.open(Native Method) at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110) at libcore.io.IoBridge.open(IoBridge.java:393) at java.io.FileOutputStream.(FileOutputStream.java:88) at org.apache.cordova.CordovaResourceApi.openOutputStream(CordovaResourceApi.java:329) at org.apache.cordova.CordovaResourceApi.openOutputStream(CordovaResourceApi.java:310) at org.apache.cordova.filetransfer.FileTransfer$4.run(FileTransfer.java:894) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) at 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>
app.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...');
});
}
Upvotes: 0
Views: 2336