有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何使用ionic cordova angularjs将所选图像发送到spring controller以保存到服务器?

如何使用ionic cordova angularjs将选定的图像发送到spring controller以保存到服务器

我在ionic+angular+cordova应用程序中有这个代码。我想使用spring restful服务发送服务器上选择的图像,以便它将图像存储在服务器/数据库上,我可以检索它吗

.controller('CameraCtrl', function ($scope, $cordovaCamera, $ionicLoading, $localstorage) {
$scope.data = { "ImageURI" :  "Select Image" };
$scope.takePicture = function() {
  var options = {
    quality: 50,
    destinationType: Camera.DestinationType.FILE_URL,
    sourceType: Camera.PictureSourceType.CAMERA
  };
  $cordovaCamera.getPicture(options).then(
    function(imageData) {
        $scope.picData = imageData;
        $scope.ftLoad = true;
        $localstorage.set('fotoUp', imageData);
        $ionicLoading.show({template: 'Foto acquisita...', duration:500});
    },
    function(err){
        $ionicLoading.show({template: 'Errore di caricamento...', duration:500});
        })
  }

  $scope.selectPicture = function() { 
    var options = {
        quality: 50,
        destinationType: Camera.DestinationType.FILE_URI,
        sourceType: Camera.PictureSourceType.PHOTOLIBRARY
    };

  $cordovaCamera.getPicture(options).then(
    function(imageURI) {
        window.resolveLocalFileSystemURI(imageURI, function(fileEntry) {
            $scope.picData = fileEntry.nativeURL;
            $scope.ftLoad = true;
            var image = document.getElementById('myImage');
            image.src = fileEntry.nativeURL;
        });
        $ionicLoading.show({template: 'Foto acquisita...', duration:500});
    },
    function(err){
        $ionicLoading.show({template: 'Errore di caricamento...', duration:500});
    })
};

$scope.uploadPicture = function() {
    $ionicLoading.show({template: 'Sto inviando la foto...'});
    var fileURL = $scope.picData;
    var options = new FileUploadOptions();
    options.fileKey = "file";
    options.fileName = fileURL.substr(fileURL.lastIndexOf('/') + 1);
    options.mimeType = "image/jpeg";
    options.chunkedMode = true;

    var params = {};
    params.value1 = "someparams";
    params.value2 = "otherparams";

    options.params = params;

    var ft = new FileTransfer();
    ft.upload(fileURL, encodeURI("http://www.yourdomain.com/upload.php"), viewUploadedPictures, function(error) {$ionicLoading.show({template: 'Errore di connessione...'});
    $ionicLoading.hide();}, options);
}

var viewUploadedPictures = function() {
    $ionicLoading.show({template: 'Sto cercando le tue foto...'});
    server = "http://www.yourdomain.com/upload.php";
    if (server) {
        var xmlhttp = new XMLHttpRequest();
        xmlhttp.onreadystatechange=function(){
        if(xmlhttp.readyState === 4){
                if (xmlhttp.status === 200) {                    
            document.getElementById('server_images').innerHTML = xmlhttp.responseText;
                }
                else { $ionicLoading.show({template: 'Errore durante il caricamento...', duration: 1000});
                return false;
                }
            }
        };
        xmlhttp.open("GET", server , true);
        xmlhttp.send()} ;
    $ionicLoading.hide();
}

$scope.viewPictures = function() {
    $ionicLoading.show({template: 'Sto cercando le tue foto...'});
    server = "http://www.yourdomain.com/upload.php";
    if (server) {
        var xmlhttp = new XMLHttpRequest();
        xmlhttp.onreadystatechange=function(){
        if(xmlhttp.readyState === 4){
                if (xmlhttp.status === 200) {                    
            document.getElementById('server_images').innerHTML = xmlhttp.responseText;
                }
                else { $ionicLoading.show({template: 'Errore durante il caricamento...', duration: 1000});
                return false;
                }
            }
        };
        xmlhttp.open("GET", server , true);
        xmlhttp.send()} ;
    $ionicLoading.hide();
}

})

我需要给出spring rest post URL,而不是php URL,该URL将进入spring java控制器。如何编写控制器来检索图像信息,然后应用业务逻辑


共 (0) 个答案