inProgress-team / inProgress-team/react-native-meteor

Error while trying to upload image from react-native

Open
#348 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
688
Forks
200
PR merge metrics
No merged PRs in 30d

Description

Hello, please help me. I have a serious problem, and i don't know how to fix that.
I'm using react native (and expo) with react-native-meteor and I'm trying to upload an image to meteor (FSCollection) and i get this error **[TypeError: (0, _Collection.default) is not a function. (In '(0, _Collection.default)(collectionName)', '(0, _Collection.default)' is undefined)]**

here is my code on client (react-native)
```
import React, { Component } from "react";
import { View } from "react-native";
import { Button, Text } from "native-base";
import * as ImagePicker from "expo-image-picker";
import Meteor, { withTracker } from "react-native-meteor";

class Profil extends Component {
upload = async file => {
try {
if (this.props.imagesReady) {
console.log("images ready", this.props.Images.find());
this.props.Images.insert(file.uri, (err, fileObj) => {
if (err) {
console.log("error upload", err);
} else {
console.log("fileObj", fileObj);
}
});
}
} catch (e) {
console.log("upload error catch", e);
}
};
getImages = async () => {
try {
const options = {
mediaTypes: ImagePicker.MediaTypeOptions.Images
};
const result = await ImagePicker.launchImageLibraryAsync(options);
console.log("result", result);
this.upload(result.uri);
} catch (e) {
console.log("error getImages", e);
}
};
render() {
return (

{this.props.imagesReady ? (

Get Images

) : null}

);
}
}

export default Meteor.withTracker(params => {
const handle = Meteor.subscribe("Images.all");
return {
imagesReady: handle.ready(),
Images: Meteor.FSCollection("Images")
};
})(Profil);
```
here is my code on meteor server :
```
import { Meteor } from "meteor/meteor";
import { FS } from "meteor/cfs:base-package";
import { GridFS } from "meteor/cfs:gridfs";

const imageStore = new FS.Store.GridFS("images", {
mongoUrl: "xxxxxxxxxxxxxx" // < -- My mongoUrl here
});

export const Images = new FS.Collection("Images", {
stores: [imageStore]
});

if (Meteor.isServer) {
Meteor.publish("Images.all", function() {
return Images.find();
});
Images.allow({
insert: function() {
// add custom authentication code here
return true;
},
update: function() {
return true;
},
download: function() {
return true;
}
});
}
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.