【问题标题】:Cordova file upload - windows visual studio android emulatorCordova 文件上传 - windows visual studio android 模拟器
【发布时间】:2015-05-06 16:30:09
【问题描述】:

我使用 Visual Studio 2015 RC 编写了一个简单的 cordova 应用程序。 该应用程序只需拍照并上传即可。非常基础,网上到处都有这方面的代码示例。

我有:

  • 设置一个空白的 Apache Cordova 应用程序。
  • 添加了相机插件
  • 添加了文件插件
  • 添加了文件传输插件

我添加了拍照然后上传到 WebAPI 站点的代码

对于上传,我从 Cordova API 文档站点添加了以下示例代码:

$scope.upload = function(imageURI) {
        var options = new FileUploadOptions();
        options.fileKey="file";
        options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1);
        options.mimeType="image/jpeg";

        var params = {};
        params.value1 = "test";
        params.value2 = "param";

        options.params = params;

        var ft = new FileTransfer();
        ft.upload(imageURI, encodeURI("http://some.server.com/upload.php"), win, fail, options);
    }

    function win(r) {
        console.log("Code = " + r.responseCode);
        console.log("Response = " + r.response);
        console.log("Sent = " + r.bytesSent);
    }

    function fail(error) {
        alert("An error has occurred: Code = " + error.code);
        console.log("upload error source " + error.source);
        console.log("upload error target " + error.target);
    }

我已将用于传输的 url 指向一个有效的真实 url。 在我的 html 中添加了 ng-click="upload()"。

当我通过任何 android 模拟器运行它时,一切都很好,直到它发送文件,什么都没有发生。

我已经使用提琴手查看任何请求,当我尝试上传时根本没有任何活动。

我已经通过打开模拟器浏览器并在互联网上导航来检查模拟器是否有网络连接,这很好。

任何想法为什么当 ft.upload 发生时它根本不上传??

【问题讨论】:

标签: angularjs visual-studio cordova ionic-framework visual-studio-cordova


【解决方案1】:

根据我之前的经验,模拟器无法使用某些插件,您可以尝试将您的Android手机连接到电脑并使用调试模式并选择“设备”尝试上传文件

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-12-11
    • 1970-01-01
    • 2017-02-12
    • 2015-03-30
    • 2016-10-13
    • 2019-04-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多