0.1.18 • Published 8 years ago

meteor-uploadable v0.1.18

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

Uploadable

A package enabling the upload and linking of files to models. For example a post in a feed could files attached to it. This package takes care of uploading (using edgee:slingshot), authorising (using coniel:can) and linking the file to a model simply by passing in an instance of the model.

UploadableModel

UploadableModel is used to add uploading capabilities to a model that is built on the coniel:base-model class. To make a model uploadable just call UploadableModel.makeUploadable(Model, "typeAsString", options) passing in a model class, a string that will be used to tag the comment records for later retrieval and optional options.

var Post = BaseModel.extendAndSetupCollection("posts");

UploadableModel.makeUploadable(Post, "post");

This will add the following methods to the prototype of the model.

files(sortKey, sortOrder) - returns an array of files that are linked to this instance of a model.

images(sortKey, sortOrder) - returns an array of files which are images that are linked to this instance of a model.

fileUploads(sortKey, sortOrder) - returns an array of edge:slingshot upload objects that are linked with this instance of a model.

fileCount() - returns the number of files for this instance of a model.

FileUpload

The FileUpload class handles the actual uploading. It uses edgee:slingshot to perform the upload so you will need to configure it first (check out the slingshot docs on how to do that).

To upload a file and attach it to a model instance, call FileUpload(model, files, slingshotDirectiveName, callbacks);

model - the model to which you want to link the file(s).

files - an array of files (e.g. taken from a file input on change: event.target.files).

slingshotDirectiveName - the slingshot directive used to enforce rules (such as file type and max size) on the file upload. These are defined when configuring slingshot (check the slingshot docs).

callbacks - an object containing callback methods to call at different stages of the upload (see example below).

var post = Meteor.posts.findOne();

var callbacks = {
    onUploadSuccess: (file) => {
        console.log('upload succeeded');
    },
    onUploadStart: (file) => {
        console.log('upload started');
    },
    onUploadError: (error, file) => {
        console.log('upload failed');
    }
};

FileUpload.upload(post, files, "image", callbacks);

File - Extends LinkableModel - Implements UploadableModel

A file is a record of a an uploaded file containing meta data such as its size, mime type, original name...

Instance Methods

user() - Returns an instance of the user that uploaded the file.

0.1.18

8 years ago

0.1.16

8 years ago

0.1.15

8 years ago

0.1.14

8 years ago

0.1.13

8 years ago

0.1.12

8 years ago

0.1.11

8 years ago

0.1.10

8 years ago

0.1.9

8 years ago

0.1.8

8 years ago

0.1.7

8 years ago

0.1.6

8 years ago

0.1.5

8 years ago

0.1.4

8 years ago

0.1.3

8 years ago

0.1.2

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago