PhoneGap文件传输错误1,在哪里写FileTransfers

PhoneGap File Transfer Error 1, where to write FileTransfers?

本文关键字:在哪里 FileTransfers 文件 传输错误 PhoneGap      更新时间:2023-09-26

与:https://stackoverflow.com/questions/21044197/download-file-and-store-them-locally-in-sdcard-using-phonegapbuild相关,但这个问题一直没有答案。

关于这个应用程序,我正在写一个小的应用程序,显示一堆pdf的,它是用jquerymobile + phonegap编写的,它是用phonegap构建服务构建的。

我意识到这个函数不能工作,因为根目录不是一个写任何东西的有效地方。但是,我无法获得我的应用程序的工作目录,也无法通过文档弄清楚错误代码1的确切含义。

从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" />

构建服务告诉我这些插件已经成功添加。

打开apk并查看清单也显示

 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

已成功添加。

最后但并非最不重要的是,使用 将phonegap库成功添加到文档中
<script type="text/javascript" charset="utf-8" src="phonegap.js"></script>

,然后只剩下实际的函数应该受到指责:

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);
});

使用警报,下面是我得到的:

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
       }

我已经调试这个好几天了,请有人有解决方案。

嘿,来看看我的答案-

Phonegap -从url保存图像到设备图片库

并让我知道。如果还有什么问题。在config.xml

中包含以下内容

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中添加以下内容-在plugin.xml中添加权限,在config.xml中添加插件名

插件检查网络连接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" />

For IOS -

<plugin name="NetworkStatus" value="CDVConnection" />