📜 ⬆️ ⬇️

Meteor. And now loading photos

It's very simple (yeah, when there is an example).

[ demo ] - multiboot with progress bars, registration is required.
[ source ] - comments on the code below.

one)
Start Meteor.
$ meteor create meteor-demo-cfs $ cd meteor-demo-cfs $ meteor 
In order not to interfere with the terminal screen, I run in the console [ctrl] + [alt] + [f4]; switch back by [ctrl] + [alt] + [f7]. This is in Ubuntu.

2)
I edit ./meteor/packages - gentlemen's set of packages.
 meteor-platform coffeescript less mquandalle:jade accounts-password ian:accounts-ui-bootstrap-3 twbs:bootstrap cfs:standard-packages cfs:filesystem cfs:gridfs cfs:ui 
Meteor will deliver everything as soon as the file is saved.
')
3)
I delete the tops - all files from the project root (.js, .html, .css). Adding: main.coffee, main.jade, main.less.

four)
main.coffee
 #    cl = (something) -> console.log(something) #    config = admin: email: 'demo@example.com', password: '12345678' if Meteor.isServer Meteor.startup -> if Meteor.users.find().count() is 0 seedUserId = Accounts.createUser email: config.admin.email, password: config.admin.password # photoStore -    ,    # https://github.com/CollectionFS/Meteor-CollectionFS#storage-adapters if Meteor.isClient # photoStore = new FS.Store.FileSystem 'photos' photoStore = new FS.Store.GridFS 'photos' if Meteor.isServer # photoStore = new FS.Store.FileSystem 'photos' photoStore = new FS.Store.GridFS 'photos', # mongoUrl: 'mongodb://127.0.0.1:27017/test/', # optional, defaults to Meteor's local MongoDB # mongoOptions: {...}, # optional, see note below # transformWrite: myTransformWriteFunction, # optional # transformRead: myTransformReadFunction, # optional # maxTries: 1, # optional, default 5 # chunkSize: 1024*1024 # optional, default GridFS chunk size in bytes (can be overridden per file). # # Default: 2MB. Reasonable range: 512KB - 4MB {} #    Photos = new FS.Collection 'photos', stores: [photoStore] filter: allow: contentTypes: ['image/*'] # allow only images in this FS.Collection #    https://github.com/CollectionFS/Meteor-CollectionFS#security Photos.allow insert: (userId, file) -> userId and file.metadata?.userId is userId update: (userId, file, fieldNames, modifier) -> userId and file.metadata?.userId is userId remove: (userId, file) -> userId and file.metadata?.userId is userId download: (userId, file, shareId) -> true fetch: ['metadata.userId', 'original'] if Meteor.isClient #     newUpload = [] Meteor.startup -> Tracker.autorun -> if not Meteor.userId() # reset,     newUpload = [] Template.hello.events 'change input[type="file"]': (event, template) -> # FileAPI http://caniuse.com/#search=fileapi #  http://habrahabr.ru/company/mailru/blog/201010/ files = event.target.files count = files.length i = 0 while i < count newFile = new FS.File(files[i]) #      https://github.com/CollectionFS/Meteor-CollectionFS#add-custom-metadata-to-a-file-before-inserting newFile.metadata = userId: Meteor.userId() Photos.insert newFile, (error, file) -> throw error if error # If !error, we have inserted new doc with ID file._id, and # kicked off the data upload using HTTP cl file i++ Template.hello.helpers #    mongo- photos: -> Photos.find() #    progress-bar isNewUpload: -> if newUpload.indexOf(this._id) + 1 return true unless this.isUploaded() newUpload.push(this._id) return true return false #    http://ru.discovermeteor.com/chapters/publications-and-subscriptions/ if Meteor.isServer Meteor.publish 'photos', (limit) -> check(arguments, [Match.Any]) [ Photos.find({}, {limit: limit}) ] if Meteor.isClient Meteor.subscribe 'photos', 100 


five)
I publish.
 $ meteor deploy demo-cfs.meteor.com 


Stsylki.

Source: https://habr.com/ru/post/248875/


All Articles