Skip to content

Instantly share code, notes, and snippets.

@joadr
Created October 6, 2016 01:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joadr/458429b05d72b0b3a8d9ff0ec096a1e5 to your computer and use it in GitHub Desktop.
Save joadr/458429b05d72b0b3a8d9ff0ec096a1e5 to your computer and use it in GitHub Desktop.
Upload files to gridFS server side using vsivi:file-collection meteor package
uploadImage = function (itemCode) {
// get the image link
var image = Meteor.call('getImageLink', itemCode)
// Upload to gridFs (vsivi:file-collection)
var imageStream = fc.upsertStream({ filename: itemCode + '.jpg',
contentType: 'image/jpeg',
metadata: {}
})
// pipe the image request to gridFs
var requestImage = request(image)
requestImage.pipe(imageStream)
// object for filesystem (prevent corruption (The same style that Orionjs uses))
var filesystem = {
url: '/gridfs/data/id/' + imageStream.id,
meta: { gridFS_id: imageStream.id },
name: itemCode + '.jpg',
uploader: 'Server',
uploadedBy: 'Joadr-server'
}
// Insert the image data on collection
var fileId = orion.filesystem.collection.insert(filesystem)
return {
fileId: fileId,
url: '/gridfs/data/id/' + imageStream.id,
info: {}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment