Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cordova Camera将空文件发送到ASP.net服务器_Asp.net_Cordova - Fatal编程技术网

Cordova Camera将空文件发送到ASP.net服务器

Cordova Camera将空文件发送到ASP.net服务器,asp.net,cordova,Asp.net,Cordova,我正在尝试将从cordova摄像机拍摄的图像发送到我的服务器。问题是服务器正在为映像返回null。我试着信任cordovaCamera的AllHost,但无济于事,可能是什么问题?谢谢 科尔多瓦方面: .controller('MapCtrl',function($scope, $cordovaCamera, $cordovaGeolocation, StoreService, dataFactory){ $scope.getPhoto = function(){ //-------

我正在尝试将从cordova摄像机拍摄的图像发送到我的服务器。问题是服务器正在为映像返回null。我试着信任cordovaCamera的AllHost,但无济于事,可能是什么问题?谢谢

科尔多瓦方面:

.controller('MapCtrl',function($scope, $cordovaCamera, $cordovaGeolocation, StoreService, dataFactory){

$scope.getPhoto = function(){

    //--------------------- get geolocation lat long --------//
        var posOptions = {timeout: 10000, enableHighAccuracy: false};
          $cordovaGeolocation
            .getCurrentPosition(posOptions)
            .then(function (position) {
              var latitude  = position.coords.latitude
              var longitude = position.coords.longitude

              console.log("photo lat: "+latitude+" photo long: "+longitude);
            }, function(err) {
              // error
            });
    //--------------------- get geolocation lat long --------//

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

        var options = {
          quality: 100,
          //destinationType: Camera.DestinationType.DATA_URL,
          //sourceType: Camera.PictureSourceType.CAMERA,
          //allowEdit: true,
          //encodingType: Camera.EncodingType.JPEG,
          targetWidth: 320,
          targetHeight: 320,
          //popoverOptions: CameraPopoverOptions,
          saveToPhotoAlbum: false
        };

        $cordovaCamera.getPicture(options).then(function(imageData) {

          console.log(imageData);




        //----- get datetime----//
        var d = new Date();
        console.log("datetime: "+d);
        //----- get datetime----//


        //--------------------- upload image into server --------//

var server = 'http://192.168.2.50/webservice.asmx/SaveImage';
        var trustAllHosts = true;

        var ftOptions = new FileUploadOptions();
        ftOptions.fileKey = 'file';
        ftOptions.fileName = imageData.substr(imageData.lastIndexOf('/') + 1);
        ftOptions.mimeType = 'image/jpeg';
        ftOptions.httpMethod = 'POST';

        var fileTransfer = new FileTransfer();


        fileTransfer.upload(imageData, encodeURI(server), win, fail, ftOptions);

        function win(r) {
            alert("Photo uploaded");
            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(error);
            console.log("upload error source " + error.source);
            console.log("upload error target " + error.target);
        }
        //--------------------- upload image into server --------//

        }, function(err) {
          // error
          alert('Failed because: ' + err);
        });

    }, false);

}
})
注意:ImageData返回有效的URLfile:///storage/emulated/0/Android/data/com.ionicframework.ionicnavigationtest216511/cache/1442991645110.jpg

r、 responseCode返回假定为http 200 OK状态的me 200

r、 我得到了回复

注意:当我测试file==null时,它返回true。如有任何建议,将不胜感激


更新1:更改图像大小将质量降低到10,并将字节发送到112也不能解决问题。

您应该以这种方式使用摄像头插件,请仔细阅读评论

    navigator.camera.getPicture(onSuccess, onFail, { 
    destinationType: Camera.DestinationType.DATA_URL //make it FILE_URI to get image as a file
    }); 

    function onSuccess(imageData) {
        var image = imageData; // base 64 encoded string, if type is FILE_URI then will contain iamge path on device

    }

    function onFail(message) {
        alert('Failed because: ' + message);
    }

另请参阅文档

我不知道asp,但我认为此代码用于获取具有recFile名称的文件

public string SaveImage()
    {

        HttpPostedFile file = HttpContext.Current.Request.Files["recFile"];

        if (file == null)
            return null;

     //   string targetFilePath = "c:\\deposit\\" + file.FileName;
       // file.SaveAs(targetFilePath);
        return file.FileName.ToString();
    } 
但是在FileUploadOptions上,您将fileKey作为文件发送

var ftOptions = new FileUploadOptions();
        ftOptions.fileKey = 'file';
        ftOptions.fileName = imageData.substr(imageData.lastIndexOf('/') + 1);
        ftOptions.mimeType = 'image/jpeg';
        ftOptions.httpMethod = 'POST';

因此,将fileKey更改为recFile或将asp代码更改为go the file

图像文件可以发送,现在是服务器无法获取该文件。我使用的是ionic plus cordova。如果您将摄像头目标类型设置为FILE_URI,那么您的上传代码或服务器站点上的图像解码可能会出现问题……我对此无能为力,因为我不熟悉服务器端编码
public string SaveImage()
    {

        HttpPostedFile file = HttpContext.Current.Request.Files["recFile"];

        if (file == null)
            return null;

     //   string targetFilePath = "c:\\deposit\\" + file.FileName;
       // file.SaveAs(targetFilePath);
        return file.FileName.ToString();
    } 
var ftOptions = new FileUploadOptions();
        ftOptions.fileKey = 'file';
        ftOptions.fileName = imageData.substr(imageData.lastIndexOf('/') + 1);
        ftOptions.mimeType = 'image/jpeg';
        ftOptions.httpMethod = 'POST';