cordova 文件上传

  function upload(){
       console.log(8888888);
       var fileTransfer = new FileTransfer();
       var severUri = encodeURI("http://kedouyun.wicp.net/DH/out/method.do");
       //var file = cordova.file.documentsDirectory
       path=encodeURI(filepath);
       console.log(path);
       //传参
       var options = new FileUploadOptions();
       options.fileKey = "file";
       options.fileName = "123";
       options.mimeType = "text/plain";
       var params = {url:"http:www",age:23};
       options.params = params;
       fileTransfer.upload(path,severUri,
                           function(entry) {
                           console.log("download complete: " + entry.toURL());
                           },
                           function(error) {
                           console.log("download error source " + error.source);
                           console.log("download error target " + error.target);
                           console.log("upload error code" + error.code);
                           },
                           options
                           ,
                           false
                           );
                           fileTransfer.onprogress = function(progressEvent) {
                               if (progressEvent.lengthComputable) {
                                   console.log(progressEvent.loaded / progressEvent.total);
                               } else {
                                   loadingStatus.increment();
                               }
                           };



   }

你可能感兴趣的:(cordova)