Package implementing common file actions for HIVE applications. An example (with settings) is in the example directory.
returns an object with keys:
filename
- name of file originally uploadedfilenameOnDisk
- unique name within FileRegistry.getFileRoot()uploaded
- number of bytes transmitted to serversize
- number of bytes of the filetimestamp
- when the file was uploadeduserId
- user id of uploadermd5
- checksumthumbnail
- name of file on disk of a thumbnail generated for the file
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
returns local filesystem path used to store uploads and registered files, e.g., /home/user/app/.meteor/files
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 toinline
, but specifyattachment
to force a download dialog on the client's browserallowAccess
- 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 returntrue
to grant access and continue serving the file, orfalse
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
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
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 asfileId
is available, instead of waiting for the upload to completeattributes
- 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
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
capture an audio clip using the default recording app or in browser, and send it to the server
capture a video clip using the default video recording app, and send it to the server