【问题标题】:Phonegap:Get the file from sdcard and upload it to the FTP Server in androidPhonegap:从 sdcard 中获取文件并上传到 android 中的 FTP 服务器
【发布时间】:2014-03-20 05:22:25
【问题描述】:

我是 phonegap 开发的新手。在我的应用程序中有一个按钮,单击该按钮将打开 sdcard 的目录结构,通过选择一个文件,所选文件将上传到FTP 服务器

我试过这个链接 ftpclient ,但它没有指定如何打开目录结构和选择文件,它根本不起作用。

谁能给我以上正确的步骤或解决方案。在此先感谢。

【问题讨论】:

  • 您要上传哪种类型的文件?
  • 任何文件 .txt,.pdf,etc..Thnks.
  • 你有实现插件的想法吗?
  • 不是我第一次开发这个 phonegap 应用程序。我只是按照链接提供的所有步骤操作..但它不起作用..:(
  • 好吧,我给你一个插件实现它的链接。有什么困难可以问。

标签: android cordova ftp phonegap-plugins


【解决方案1】:

这是FileChooser 的插件,您可以选择从 SDCard 中选择文件。 cordova-filechooser。请像这样更改filechooser.js 文件

(function( cordova ) {

function FileChooser() {}

    FileChooser.prototype.open = function(win, fail) {
        return cordova.exec(
            function (args) { if(win !== undefined) { win(args); } },
            function (args) { if(fail !== undefined) { fail(args); } },
            "FileChooser", "open", []);
    };

    if(!window.plugins) {
        window.plugins = {};
    }

    if (!window.plugins.FileChooser) {
        window.plugins.FileChooser = new FileChooser();
    }

})( window.cordova );

将此js 文件添加到您的js 文件夹中。并像这样使用

plugins.FileChooser.open(function (uri) {
                // success
            alert(uri); 

            },function () {
               // fail
                alert('failed');
            }); 

【讨论】:

  • 在您的config.xml 文件中添加插件。如果您有任何疑问。你可以在这里问。
  • 很抱歉,它不起作用。我只是在 filechooser.js 中添加上面的代码,然后在我的 index.js 文件中单击按钮,我添加了第二个 ..我也导入了 filechooser.js在 index.html..plugins 中也添加了这样的..
  • 在 config.xml 添加<feature name="FileChooser"> <param name="android-package" value="com.example.eos.FileChooser" /> </feature>
  • 然后点击按钮调用我提供的最后一段代码。这是plugins.FileChooser.open
  • 不,伙计,它不起作用..我只是添加了这个插件,并在按钮单击时添加了 plugins.Fliechoser.open 但不执行任何操作。
猜你喜欢
  • 2012-07-06
  • 2018-05-12
  • 1970-01-01
  • 2019-07-08
  • 1970-01-01
  • 2014-08-08
  • 1970-01-01
  • 2018-03-07
  • 2011-02-12
相关资源
最近更新 更多