Skip to content

Simple file uploads in Meteor, and some additional media functionality

Notifications You must be signed in to change notification settings

UK-AS-HIVE/meteor-file-registry

Repository files navigation

hive:file-registry

Package implementing common file actions for HIVE applications. An example (with settings) is in the example directory.


API

FileRegistry.findOne() - anywhere

returns an object with keys:

  • filename - name of file originally uploaded
  • filenameOnDisk - unique name within FileRegistry.getFileRoot()
  • uploaded - number of bytes transmitted to server
  • size - number of bytes of the file
  • timestamp - when the file was uploaded
  • userId - user id of uploader
  • md5 - checksum
  • thumbnail - name of file on disk of a thumbnail generated for the file

FileRegistry.upload(file, [options,] cb) - client

Uploads a File or Blob to the server, and invokes cb when done uploading. The function cb will be passed a single parameter:

  • fileId - id representing the uploaded file in FileRegistry

If options is passed with the key immediate set to True, then cb will be called as soon as fileId is available, instead of waiting for the upload to complete

FileRegistry.getFileRoot() - server

returns local filesystem path used to store uploads and registered files, e.g., /home/user/app/.meteor/files

FileRegistry.serveFile - server

plug into iron:router to create a server-side route for serving uploads

FileRegistry.serveFile optionally accepts a single argument of an object with any of the following keys:

  • disposition - defaults to inline, but specify attachment to force a download dialog on the client's browser
  • allowAccess - function to verify that the requester has permissions to download the file. this inside the function will be the Express context passed into the server-side route handler. function should return true to grant access and continue serving the file, or false to generate a 403 error. If unspecified, access will be granted to any requester.

Example:

Router.route 'serveFile',
  path: '/file/:filename'
  where: 'server'
  action: FileRegistry.serveFile

FileRegistry.onUploaded(cb) - server

register a callback function to execute after an file finishes uploading. The function will be passed a single parameter:

  • fileDoc - metadata about the file, from the FileRegistry collection

Media.pickLocalFile([options,] cb) - client

opens a file selector on the client, and uploads selected files to the FileRegistry. Accepts an options object that contains any valid input tag attributes.

  • options - if specified, the following keys maybe present:
    • immediate - if set to True, then cb will be called as soon as fileId is available, instead of waiting for the upload to complete
    • attributes - if present, attributes will be added to the temporary <input> tag verbatim
  • cb - After each file in the upload completes, the passed callback function will be called with a single parameter:
    • fileId - _id of uploaded document in FileRegistry collection

Example:

Media.pickLocalFile {attributes: {multiple: true, accept: '.jpg'}}, (fileId) ->
  console.log "Completed upload of new file, ", fileId

Media.capturePhoto(cb) - client

take a photo using the default photo app or a webcam in browser, and send it to the server. After the upload completes, the passed callback function will be called with a single parameter:

  • fileId - _id of uploaded document in FileRegistry collection

Media.captureAudio() - client

capture an audio clip using the default recording app or in browser, and send it to the server

Media.captureVideo() - client

capture a video clip using the default video recording app, and send it to the server

About

Simple file uploads in Meteor, and some additional media functionality

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •