无法在Android设备上使用cordova filetransfer插件上传

时间:2016-05-04 09:44:06

标签: javascript android jquery cordova

当我点击按钮我的图片时,文件选择器会加载,但在我选择文件并点击上传按钮后没有任何反应。我希望能够将文件上传到服务器上。我还希望相机出现在文件选择器列表中。我使用把手模板结合棘轮。

这是我的代码: 的 HTML

   <p><button class="btn btn-positive" id="inputIdbtn">My Picture</button></p>
   <p>&nbsp;</p>
   <button class="btn btn-positive" id="uploadbtn">Upload</button><div id="maphotodiv"></div>
   <input id="inputId" type="file" style="position: fixed; top: -100em" accept="image/*,capture=camera">

javascript功能

  this.uploadToServer=function() {
            imageURI=document.getElementById("inputId").value;
            document.getElementById("maphotodiv").innerHTML="<p>processing...<p>"
            var options = new FileUploadOptions();
            options.fileKey="file";
            options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1);
            options.mimeType="image/jpeg";

            var params = new Object();
            params.value1 = "test";
            params.value2 = "param";

            options.params = params;
            options.chunkedMode = false;

            var ft = new FileTransfer();
            ft.upload(imageURI, "http://...", win, fail, options);


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

        var fail=function(error) {
            alert("An error has occurred: Code = " + error.code);
        };  

};

0 个答案:

没有答案