PhoneGap文件传输错误1,在哪里写FileTransfers? [英] PhoneGap File Transfer Error 1, where to write FileTransfers?
问题描述
相关:下载文件并将其存储在本地在sdcard使用PhonegapBuild ,但这个问题从未回答过。
Related to: Download File and store them locally in sdcard using PhonegapBuild but that questions has never been answered.
关于这个程序,我在写一个小应用程序,显示一堆pdf的,使用jquerymobile + phonegap编写,它正在使用phonegap构建服务。
About this app, I'm writing a little app that displays a bunch of pdf's, it's written using jquerymobile + phonegap and it's being build with the phonegap build service.
我意识到这个函数不能工作,因为根目录不是一个有效的地方写任何东西。但是,我无法得到我的应用程序的工作目录,也没有能够弄清楚什么是错误代码1的意思使用该文档。
I realize that this function cannot work, since the root-Directory is not a valid place to write anything. But, I was unable to get the working directory of my application, nor was I able to figure out what exactly Error Code 1 meant using the documentation.
从config.xml :
from config.xml:
<preference name="AndroidPersistentFileLocation" value="Internal" />
<preference name="permissions" value="none" />
<feature name="http://api.phonegap.com/1.0/file"/>
<feature name="http://api.phonegap.com/1.0/device" />
<gap:plugin name="org.apache.cordova.file" />
<gap:plugin name="org.apache.cordova.file-transfer" />
构建服务告诉我这些插件已成功添加。
And the build service tells me that these plugins have been sucessfully added.
打开apk并查看清单还会显示
Unpacking the apk and looking into the manifest also reveals that
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
已成功添加。
特别是使用
<script type="text/javascript" charset="utf-8" src="phonegap.js"></script>
,然后只剩下实际的函数:
and then there is only the actual function left that would be to blame:
function downloadFile(name, url, y,x, canvasid, wrapperid){
alert(name);
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0,
function(fileSystem) {
var directoryEntry = fileSystem.root; // to get root path to directory
var rootdir = fileSystem.root;
var fp = rootdir.fullPath;
fp = fp+"/bestsongs/"+name;
alert("downloading: " + url + " to " + fp);
var fileTransfer = new FileTransfer();
alert("downloading: " + url + " to " + fp);
fileTransfer.download(
url,
name,
function(theFile) {
alert("download complete: " + theFile.toURI());
loadPDF(theFile.toURI(), y,x, canvasid, wrapperid);
},function(error) {
alert("error: " + JSON.stringify(error));
}
);
},
function(arg) {
alert("FAIL ON requestFileSystem" + JSON.stringify(arg)); }
);
}
$(function() {
document.addEventListener("deviceready", function() {
alert("deviceready!");
try {
alert(url);
downloadFile(lyrics,url,y,x, 'the-canvas', 'wrapper');
} catch(e) {
alert(e);
}
}, false);
});
使用警报,这里是我得到的:
Using the alerts, here is what I get:
deviceready!
<url> to file (which is right)
the name of the file.
downloading <url> to //bestsongs/<name>
downloading <url> to //bestsongs/<name>
error: {
"code":1,
"source":<url>,
"target":<name>,
"http_status": null,
"body": null
}
推荐答案
看看我的回答在这里 -
Hey take a look at my answer over here -
,让我知道。如果还有任何问题。
在您的config.xml中包含以下内容
and let me know. If there is still any problem. Include following in your config.xml
对于Android -
For Android -
<feature name="http://api.phonegap.com/1.0/file" />
<feature name="File">
<param name="android-package" value="org.apache.cordova.file.FileUtils" />
</feature>
<feature name="FileTransfer">
<param name="android-package" value="org.apache.cordova.filetransfer.FileTransfer" />
</feature>
<feature name="Storage">
<param value="org.apache.cordova.Storage" name="android-package"/>
</feature>
对于IOS -
<plugin name="File" value="CDVFile" />
<plugin name="FileTransfer" value="CDVFileTransfer" />
要检查网络连接是否可用,请在config.xml中添加以下内容 -
添加权限in plugin.xml和plugins name in config.xml
For checking network connection available or not add following in your config.xml - add permissions in plugin.xml and plugins name in config.xml
插件检查网络连接
对于Android -
Plugin to check Network connection For Android -
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<plugin name="NetworkStatus" value="org.apache.cordova.NetworkManager" />
对于IOS -
<plugin name="NetworkStatus" value="CDVConnection" />
这篇关于PhoneGap文件传输错误1,在哪里写FileTransfers?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!