如何将图像作为文件发送到离子服务器

How to send the image as file to the server in ionic

我正在使用 ionic 和 ngCordova 相机插件来调用我的相机,我正在使用 base64 格式获取我的图像我不需要保存图像但我需要发送图像而不是 base64。我需要将其作为文件格式发送,有没有办法将图像作为文件发送以供我支持的是 c#。

这是我的html样子

<img ng-show="imgURI !== undefined" ng-src="{{imgURI}}">
        <img ng-show="imgURI === undefined" ng-src="http://placehold.it/250x250">
        <button class="button" ng-click="takePicture()">Take Picture</button>

我的app.js文件

$scope.takePicture = function(){
      var options = {
        quality: 50,
        destinationType: Camera.DestinationType.DATA_URL,
        sourceType: Camera.PictureSourceType.CAMERA,
        allowEdit: true,
        encodingType: Camera.EncodingType.JPEG,
        targetWidth: 250,
        targetHeight: 250,
        popoverOptions: CameraPopoverOptions,
        saveToPhotoAlbum: false,
      correctOrientation:true
      };

      $cordovaCamera.getPicture(options).then(function(imageData) {
        console.log(imageData);
        $scope.imgURI = "data:image/jpeg;base64," + imageData;
      }, function(err) {
        // error
      });
  };

  }, false);

在我的 imageData 中,我有 base64 值有没有办法将 $scope.imgURI 转换成文件,这样我就可以发送我的图像进行服务。

为什么不使用 Camera.DestinationType.FILE_URI 而不是 Camera.DestinationType.DATA_URL 作为 destinationType?

这样,您将在设备文件系统上获得一个文件;那么我想将该文件上传到您的服务器应该很容易...

然后,如果您的设备上不再需要该文件,您可以将其删除。

如果您更喜欢处理 base64,您可以检查 angular-base64-upload 模块,该模块将 base64 数据上传到服务器...