首页 > 用$cordovaFileTransfer.upload上传文件和几个参数到后台,后台怎么接收参数

用$cordovaFileTransfer.upload上传文件和几个参数到后台,后台怎么接收参数

folderService.upload = function (results, currentFolderId) {

    //console.debug("user--type-->>" + typeof user);
    var options = {
        folderId: currentFolderId,
        userId: localStorageService.getLocalStorage("user").userId
    };

    for(var i=0;i<results.length;i++){
        console.debug("result-->>"+results[i]+"      $$$$options---->>"+angular.toJson(options));
    $cordovaFileTransfer.upload(URL + "file/fileupload.do", results[i], options).then(function (result) {

    }, function (err) {
        console.error("ERROR: " + angular.toJson(err));
    }, function (progress) {
        // constant progress updates
    });
    }
};

后台用springMVC接收的,请问后台如何接收options 的2个参数folderId和userId,我试过了各种办法,后台就是接收不到这2个参数。

下面是该组件的官方文档:
$cordovaFileTransferSource Official Docs
This plugin allows you to upload and download files.

cordova plugin add org.apache.cordova.file-transfer
Methods

download(url, filePath, options, trustHosts)

Downloads a file from server.

Param Type Detail
url String URL of the server to download the file
targetPath String Filesystem url representing the file on the device
options Object Optional parameters, currently only supports headers
trustAllHosts Boolean If set to true - accepts all security certificates
Returns Type Detail
success Object Returns success object with file path and more info
progress Object Returns download progress Object
upload(server, filePath, options, trustAllHosts)

Sends a file to a server.

Param Type Detail
server String URL of the server to receive the file
targetPath String Filesystem url representing the file on the device
options Object Optional parameters
trustAllHosts Boolean If set to true - accepts all security certificates
Returns Type Detail
success Object Returns success object with file path and more info
progress Object Returns download progress Object
Example

module.controller('MyCtrl', function($scope, $timeout, $cordovaFileTransfer) {

document.addEventListener('deviceready', function () {

var url = "http://cdn.wall-pix.net/albums/art-space/00030109.jpg";
var targetPath = cordova.file.documentsDirectory + "testImage.png";
var trustHosts = true
var options = {};

$cordovaFileTransfer.download(url, targetPath, options, trustHosts)
  .then(function(result) {
    // Success!
  }, function(err) {
    // Error
  }, function (progress) {
    $timeout(function () {
      $scope.downloadProgress = (progress.loaded / progress.total) * 100;
    })
  });

}, false);

document.addEventListener('deviceready', function () {

$cordovaFileTransfer.upload(server, filePath, options)
  .then(function(result) {
    // Success!
  }, function(err) {
    // Error
  }, function (progress) {
    // constant progress updates
  });

}, false);

});

【热门文章】
【热门文章】