Created
October 6, 2016 01:50
-
-
Save joadr/458429b05d72b0b3a8d9ff0ec096a1e5 to your computer and use it in GitHub Desktop.
Upload files to gridFS server side using vsivi:file-collection meteor package
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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