【问题标题】:How to send the image as file to the server in ionic如何在离子中将图像作为文件发送到服务器
【发布时间】:2016-04-01 18:50:01
【问题描述】:

我正在使用 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 转换为文件,这样我就可以发送我的图像来服务了。

【问题讨论】:

    标签: angularjs image ionic-framework cordova-plugins ngcordova


    【解决方案1】:

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

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

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

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

    【讨论】:

    • 是的,你是对的,我看到了那个选项,但是在使用了这个 **$cordovaCamera.getPicture(options).then(function(imageURI) { var image = document.getElementById('myImage'); image .src = imageURI; }, ** 我不知道要发给服务器哪个是我的文件在哪里
    • 我是 ionic 新手,请帮助我
    • 使用Camera.DestinationType.FILE_URI,在imageURI你得到base64格式的图像内容。在那里,您应该调用 angular-base64-upload 模块,传递 base64 数据和您的服务器 url。
    • 当我有 FILE_URI 我无法显示图像但在 android 中工作正常时,我遇到了 ios 设备的问题
    猜你喜欢
    • 1970-01-01
    • 2020-10-05
    • 1970-01-01
    • 2018-09-21
    • 2018-10-11
    • 2019-11-04
    • 1970-01-01
    • 2014-09-19
    • 1970-01-01
    相关资源
    最近更新 更多