Meteor 和 React Native - 文件集合访问
我不久前在 FilesCollection Github Repo 上发布了这个问题(https://github.com/veliovgroup/Meteor -Files),但我希望能在这里联系到任何熟悉 Meteor 和 React Native 的人。
我的问题是,我不确定如何将 FilesCollection 与 React Native (RN) 和 Meteor 一起使用。
我使用官方 Meteor 指南来设置 RN 应用程序: https://guide.meteor.com /react-native.html
所以我可以访问 @meteorrn/core
但现在我怎么可能访问 FileCollection。
通常你会这样做(在非 RN Web 应用程序上):
import { FilesCollection } from "meteor/ostrio:files";
export const ImageDB = new FilesCollection(chosenSettings);
其中 chosenSettings
是一些设置可能是例如
const chosenSettings = {
collectionName: "Images",
allowClientCode: false,
onBeforeUpload(file) {
if (file.size <= 10485760 && /png|jpg|jpeg/i.test(file.extension)) {
return true;
}
return "Please upload image, with size equal or less than 10MB";
},
storagePath: `${process.env.PWD}/images`,
};
但是,使用 RN 无法访问 FilesCollection
来自 meteor/ostrio:files
因为我在这里没有任何流星关系
对于其他集合,我可以使用来自 @meteorrn/core
的 Mongo.Collection
>,但这对于 FilesCollection 来说是不可能的:
const collection = new Mongo.Collection("myCollection");
有什么建议吗?
i posted this question some time ago at the FilesCollection Github Repo (https://github.com/veliovgroup/Meteor-Files), but I'll hope to reach out here anyone who is familiar with Meteor and React Native.
My problem is, that I'm not sure how to use a FilesCollection with React Native (RN) and Meteor.
I used the official Meteor guide to set up a RN app: https://guide.meteor.com/react-native.html
So i have access to @meteorrn/core
but how is it now possible for me to access a FileCollection.
Usually you would do this with (on a non-RN-web app):
import { FilesCollection } from "meteor/ostrio:files";
export const ImageDB = new FilesCollection(chosenSettings);
where chosenSettings
are some settings might be e.g.
const chosenSettings = {
collectionName: "Images",
allowClientCode: false,
onBeforeUpload(file) {
if (file.size <= 10485760 && /png|jpg|jpeg/i.test(file.extension)) {
return true;
}
return "Please upload image, with size equal or less than 10MB";
},
storagePath: `${process.env.PWD}/images`,
};
However, with RN it is not possible to access FilesCollection
from meteor/ostrio:files
as I don't have any meteor relation here
With other collections I can use Mongo.Collection
from @meteorrn/core
, however this is not possible with FilesCollection:
const collection = new Mongo.Collection("myCollection");
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不存在“开箱即用”的解决方案,因为 RN 客户端上没有可用的 FilesCollection。但是,您可以使用 Meteor 方法创建解决方法策略。
服务器
服务器
这假设您已订阅了图像集合,如图所示在指南中。
客户端
资源
There is no "out-of-the-box" solution, as there is no FilesCollection on the RN client available. However, you could create a workaround strategy using a Meteor method.
server
server
This assumes you have subscribed to the Image Collection as shown in the guide.
client
Resources