veliovgroup / Meteor-Files

🚀 Upload files via DDP or HTTP to ☄️ Meteor server FS, AWS, GridFS, DropBox or Google Drive. Fast, secure and robust.
https://packosphere.com/ostrio/files
BSD 3-Clause "New" or "Revised" License
1.11k stars 166 forks source link

Question: Can you store directly in GridFS? #872

Closed Gobliins closed 11 months ago

Gobliins commented 1 year ago

Hey,

currently my flow is like this:

When someone uploads a file it's first saved as a file on the filesystem and later after upload, the file is moved into GridFS. Similar to https://github.com/veliovgroup/Meteor-Files/wiki/GridFS-Integration

My (approximately) Code:


// GridFS Bucket create
createBucket = (bucketName) => {
  const options = bucketName ? { bucketName } : void 0;
  return new MongoInternals.NpmModule.GridFSBucket(
    MongoInternals.defaultRemoteCollectionDriver().mongo.db,
    options,
  );
};

export const Files = new FilesCollection({
  ....
  // move uploaded File from FS to GridFS
  onAfterUpload(fileObj) {
    const readStream = fs.createReadStream(filepath); // FS Read
    const writeStream = this.gridFsBucket.openUploadStream(filepath); // GridFS Write
    readStream.pipe(writeStream)
    ...
   // unlink from FS
  },
...

So when adding Files via the Files.load() or Files.insert() methods, is it possible to skip the Filesystem and upload / load / add files, directly into GridFs?

Regards

dr-dimitru commented 1 year ago

@Gobliins I understand your frustration but there's no way to skip local file system as intermediate point

Gobliins commented 1 year ago

@dr-dimitru No worries, just wanted to know :)