orionjs:filesystem

v0.0.17Published 11 years ago

This package has not had recent updates. Please investigate it's current state before committing to using it in your project.

Orion Filesystem

The filesystem module is a unified upload system that keep track of all the files that are uploaded to orion and use any provider you want.

alt tag

Getting Started

Install filesystem

meteor add orionjs:filesystem

Install the provider (currently the only one is S3. To use S3 need to config some things, see here)

meteor add orionjs:s3

Creating a Provider

You can setup a provider and orion will automatically upload all the files through this, and all packages in compatible with orion should too.

Provider Upload

1orion.filesystem.providerUpload(options, success, failure)
  • option Object. Attribute that will contain information about the upload.

But the only important thing is option.fileList, which is equivalent to $(".fileinput")[0].files. It only contains one file.

  • success(publicUrl, [meta]) Function. When the file is uploaded call this function so orion

can register the file in the database and we can see it in the admin.

- ```publicUrl``` **String**. The url of the uploaded file.

- ```meta``` **Object**. A object containing whatever you want. For example 
you can save here the local path of the file.
  • failure(error) Function. If the upload fails call this function.

    • error Object. The upload error description.

Example:

1// Official S3 Upload Provider
2orion.filesystem.providerUpload = function(options, success, failure) {
3	/**
4     * Here you will recive the file in the variable options.fileList.
5     *
6     * You have to upload the file using the method you want.
7     *
8     * If the file was uploaded successfully call success(fileUrl, optionalData)
9     * The optionalData will be saved in the meta variable
10     *
11     * If not call failure(error).
12     */
13	S3.upload(options.fileList, "/orionjs", function(error, result) {
14		if (error) {
15			failure(error);
16		} else {
17			success(result.url, { s3Path: result.relative_url });
18		}
19    	
20    });
21}

Provider Remove

1orion.filesystem.providerRemove(file, success, failure)
  • file Object. The object representing the file.

  • success() Function. When the file is removed call this function so orion

can delete the file from the database.

  • failure(error) Function. If the remove fails call this function.

    • error Object. The remove error description.

Example:

1// Official S3 Remove Provider
2orion.filesystem.providerRemove = function(file, success, failure)  {
3	/**
4     * Here you will recive the file object, containing the url and 
5     * the optionalData in file.meta.
6     *
7     * You have remove the file.
8     *
9     * If the file was removed successfully call success()
10     *
11     * If not call failure(error).
12     */
13	S3.delete(file.meta.s3Path, function(error, result) {
14		if (error) {
15			failure(error);
16		} else {
17			success();
18		}
19	})
20}

Uploading Files Through Filesystem

If you want to make an extension for orion and you need to upload files, you must use this.

Example:

1orion.filesystem.upload({
2    fileList: fileInput[0].files, 
3    name: 'file.txt', 
4    folder: 'my-extension-files', 
5    canRemove: true // Can the admin delete manually the files
6}, function(file, error) {
7    if (!error) {
8        console.log(file, "file uploaded")
9    } else {
10        console.log(error, "error uploading file")
11    }
12});

Removing Files

Example:

1var fileId = 'The id of the file';
2orion.filesystem.remove(fileId, function(error) {
3	if (!error) {
4		console.log('File removed');
5	}
6});