Meteor Cordova 图片分享应用

3

我正在构建一款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 传递(但图像未呈现)。

不确定如何继续下一步。有什么见解吗?

附注:未来的任务包括上传视频、pdf、文档和其他文件。因此,如果您的答案也可以帮助解决这些问题,将不胜感激。

1个回答

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);
    });

在函数copyFile(fileEntry)中,makeid()是指什么? - user3807691

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接