简体   繁体   中英

Meteor Files Collection showing up empty when trying to insert files on server-side?

I'm using the Meteor Files package (from https://github.com/VeliovGroup/Meteor-Files ) in my Meteor project. I want to set up a files collection but I'm having issues populating it from the server-side.

Here is my relevant code inside /server/main.js :

import { Sources } from "/imports/db/sourcesCollection";


Meteor.startup(() => {
  // code to run on server at startup

  Sources.addFile("/images/bigLogo.png", {
    fileName: "bigLogo.png",
    type: "image/png",
    fileId: "abc123AwesomeId",
    meta: {},
  })
...

And here is sourcesCollection.js :

import { FilesCollection } from "meteor/ostrio:files";

const Sources = new FilesCollection({ collectionName: "Sources" });

export { Sources };

bigLogo.png is an image png file inside the public/images directory in my project, and I've used it successfully in other files. As a sanity check, to test if this was a file-path issue, I've also tried moving my image to the same directory as my server/main.js file and changing the image path to ./bigLogo.png , but to no avail.

When my server starts up I get no error messages so it seems like addFile() is working, but when I check my collection on the server-side through the meteor shell, it always shows up as an empty collection. Here is what I'm doing to check it:

First, I run meteor shell , then import { Sources } from "imports/db/sourcesCollection.js" and finally Sources.find({}).fetch() which returns an empty array [] .

To summarize, my question is: if my code is running successfully when my server starts up, why is my collection showing up as empty in my meteor shell?

Edit: Running the .addFile() statement in the console returned a FilesCollection object, and the collection is still empty upon checking Sources.find({}).fetch() .

Edit 2: I added a callback function to display the error from addFile(). I'm getting an ENOENT error referring to the file path. The image is most definitely there and the path is correct (I've tried both in the same folder and in the public folder), so I don't know why this is happening. I've tried resetting the project and even re-installing Meteor but that didn't fix it either.

If you ever run into this issue, here is what fixed it for me:

Meteor: Error: ENOENT when trying to access an image using node-gd

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM