流星科尔多瓦图像分享应用程序

时间:2018-03-13 13:51:53

标签: image cordova meteor camera gallery

我正在构建一个METEOR应用程序,用户可以使用相机和图库点击/上传图像。其他用户应该能够看到图像并下载它。

我安装了以下插件:

cordova-plugin-camera@2.4.1,

cordova-plugin-file@4.3.3

这是我的代码:

var cameraOptions = {
    quality: 100,
    previewDrag: false,
    sourceType: sourcetype,
    correctOrientation: true,
    allowEdit: true,
    saveToPhotoAlbum : true,
    mediaType : Camera.MediaType.PICTURE,
    destinationType : Camera.DestinationType.FILE_URI,
    encodingType: Camera.EncodingType.JPEG,
    popoverOptions: CameraPopoverOptions
};
navigator.camera.getPicture(function cameraSuccess(fileURI){
    resolveLocalFileSystemURL(dataURL, function(entry) {
        Session.set('imgData', entry.toInternalURL());          
    });
}, function cameraError(error){
    Session.set('imgData', false);
}, cameraOptions);`

Session.get(' imgData')作为img src传递(图片无法渲染)

不知道怎么办。任何见解??

PS:未来的任务还包括iploading video,pdf,docs和其他文件。因此,对此有帮助的答案将受到高度赞赏。

1 个答案:

答案 0 :(得分:0)

以下是获取图片的代码。 这部分是为了获得形象。

function onCopySuccess(entry) {
    $scope.$apply(function () {
        $scope.image = entry.nativeURL;
    });
}

这里是关于拍照和获取图像的完整代码。 你应该安装cordova-plugin-file插件。

// 2
    var options = {
        destinationType : Camera.DestinationType.FILE_URI,
        sourceType : Camera.PictureSourceType.CAMERA, // Camera.PictureSourceType.PHOTOLIBRARY
        allowEdit : false,
        encodingType: Camera.EncodingType.JPEG,
        popoverOptions: CameraPopoverOptions,
    };

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

        // 4
        onImageSuccess(imageData);

        function onImageSuccess(fileURI) {
            createFileEntry(fileURI);
        }

        function createFileEntry(fileURI) {
            window.resolveLocalFileSystemURL(fileURI, copyFile, fail);
        }

        // 5
        function copyFile(fileEntry) {
            var name = fileEntry.fullPath.substr(fileEntry.fullPath.lastIndexOf('/') + 1);
            var newName = makeid() + name;

            window.resolveLocalFileSystemURL(cordova.file.dataDirectory, function(fileSystem2) {
                fileEntry.copyTo(
                    fileSystem2,
                    newName,
                    onCopySuccess,
                    fail
                );
            },
            fail);
        }

        // 6
        function onCopySuccess(entry) {
            $scope.$apply(function () {
                $scope.image = entry.nativeURL;
            });
        }

        function fail(error) {
            console.log("fail: " + error.code);
        }     
    }, function(err) {
        console.log(err);
    });