【问题标题】:Ionic: save camera images to device and upload later离子:将相机图像保存到设备并稍后上传
【发布时间】:2016-12-19 09:28:22
【问题描述】:

我正在构建一个使用 cordova-camera 插件的应用程序。现在我可以访问设备摄像头并获取文件 URL..

我想将图像和图像路径存储到 localstorage 中,并在以后设备上线时用于上传。

这是我目前的代码

控制器

$scope.takePhoto = function(){
    var element = event.target;
        var options = {
          quality: 75,
          destinationType: Camera.DestinationType.FILE_URL,
          sourceType: Camera.PictureSourceType.CAMERA,
          allowEdit: true,
          encodingType: Camera.EncodingType.JPEG,
          targetWidth: 100,
          targetHeight: 100,
          popoverOptions: CameraPopoverOptions,
          saveToPhotoAlbum: false,
          correctOrientation:true
        };

        $cordovaCamera.getPicture(options).then(function(imageData) {
            $scope.imageURI = "data:image/jpeg;base64," + imageData;
            angular.element(element).closest('.input-group').find('.input-container').val($scope.imageURI)
            console.log(angular.element(element).closest('.input-group').find('.input-container').attr('id'));

        $cordovaFile.moveFile(cordova.file.applicationDirectory, imageData, cordova.file.externalRootDirectory)
              .then(function (success) {
                console.log('success')
              }, function (error) {
                console.log(error)
              });

        }, function(err) {
            console.log(err)
        });
    console.log();
}

HTML

<div class="form-group">
        <label for="factory_gate" class="label-control">Factory Gate</label>
        <div class="input-group">
            <input type="text" class="form-control input-container" id="factory_gate" ng-model="factory_gate" placeholder="">
            <span class="input-group-btn">
            <button class="btn btn-secondary btn-success" type="button" ng-click="takePhoto($event)">
                <i class="icon ion-android-camera"></i>
            </button>
            </span>
        </div>
    </div>

我怎样才能实现我的输出?我已经安装了cordova文件插件..

【问题讨论】:

    标签: android ios angularjs cordova


    【解决方案1】:

    好的,所以一旦您有了文件 URL,您所要做的就是存储它,一个不错的选择是 https://github.com/gsklee/ngStorage。您可能必须对其进行字符串化才能正确存储,因此请使用log 检查它是否已正确存储,然后在设备在线后使用http://ngcordova.com/docs/plugins/fileTransfer/ 上传图像。有任何问题,请见谅。

    【讨论】:

      猜你喜欢
      • 2012-11-16
      • 1970-01-01
      • 2019-01-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-26
      • 1970-01-01
      相关资源
      最近更新 更多