无法将图像从RN应用程序上传到流星后端

时间:2018-01-17 08:53:32

标签: meteor react-native

我想将我的RN应用程序中的图像上传到流星后端。我正在使用" react-native-image-picker":" ^ 0.26.7"用于从图库或相机获取图像文件并使用package react-native-meteor上传到meteors这是我的RN应用程序代码,我用户选择图像后立即调用meteor方法进行图像上传:

_handleSelectFile() {
    const { order } = this.state;
    var options = {
        title: 'Select Avatar',
        storageOptions: {
            skipBackup: true,
            path: 'images'
        }
    };
    ImagePicker.showImagePicker(options, (response) => {
        if (response.didCancel) {
            console.log('User cancelled image picker');
        }
        else if (response.error) {
            console.log('ImagePicker Error: ', response.error);
        }
        else {
            // let source = { uri: response.uri };

            // You can also display the image using data:
            let source = { uri: 'data:image/jpeg;base64,' + response.data };
            this.setState({
                order: {
                    ...order,
                    fileName: response.fileName
                }
            });
            let fileData = response.data;
            // const body = new FormData();
            // body.append('file',fileData);
            var photo = {
                url: fileData,
                type: 'image/jpeg',
                name: 'photo.jpg',
            };
            Meteor.FSCollection('orderImages').insert(photo, function (err, res) {
                if (err) {
                    console.log('error during uploading');
                } else {
                    console.log('uploading successfully');
                    // _this.props.navigator.pop();
                }
            });
        }
    });
}

这是我的服务器端代码:

export const Orders = new Mongo.Collection('orders');
export const OrderImages = new FS.Collection("orderImages", {
    filter: {
        maxSize: 1048576,
        allow: {
            contentTypes: ['image/*'],
        }
    },
    stores: [new FS.Store.FileSystem("orderImages")]
});

if (Meteor.isServer) {    
    OrderImages.allow({
        insert: function () {
            return true;
        }
    });    
}

我收到的错误是这样的: ExceptionsManager.js:65

  

无法阅读财产'申请'未定义的

0 个答案:

没有答案