Provides Vulcan with the ability to upload files to the server and store them using Meteor-Files.
This package requires Vulcan 1.11.0
or greater.
In your project's root folder run:
meteor add origenstudio:vulcan-files
To avoid using Npm.depends
this package does not include any NPM module, so you will have to install them yourself by running the following command:
meteor npm install async-busboy@^0.6.2 brackets2dots@^1.1.0 lodash@^4.0.0 object-path@^0.11.4 randomstring@^1.1.5 react-dropzone@^3.12.2 recursive-iterator@^3.3.0 knox@^0.9.2 gm@^1.23.1
Alternatively, here you have a list of the packages and versions required, so you can add them to your project's package.json
:
{
"async-busboy": "^0.6.2",
"brackets2dots": "^1.1.0",
"gm": "^1.23.1",
"knox": "^0.9.2",
"lodash": "^4.0.0",
"object-path": "^0.11.4",
"randomstring": "^1.1.5",
"react-dropzone": "^3.12.2",
"recursive-iterator": "^3.3.0"
}
Make sure you run meteor npm install
.
One problem of directly working with Meteor-Files is that files collection can only be created in a server context. This module exports a createFSCollection
function both on the server and client (the latter is just a stub) so it can be called anywhere.
import { createFSCollection } from 'meteor/origenstudio:vulcan-files';
const MyFSCollection = createFSCollection({
collectionName: 'MyFSCollection',
// ...other FilesCollection options
});
if (Meteor.isClient) {
console.log(MyFSCollection); //-> undefined
}
This module provides a generateFieldSchema
function that will handle many of the problematics of adding a file field, while allowing you to customize (almost) all of its features.
// TODO add documentation, see `Vulcanstagram` example for now
Right now only Amazon S3 is supported.
You can create an S3 client easily with the createS3Client
function: you only need to provide it your bucket configuration and your CloudFront domain. As always, a stub function is exported in client so you can use this function anywhere.
Since you'll want to have your S3 configuration in your settings, you can retrieve them with Vulcan's getSetting
function.
{
"amazonAWSS3": {
"mainBucket": {
"cfdomain": "https://yourdomain.cloudfront.net",
"client": {
"key": "",
"secret": "",
"region": "eu-west-1",
"bucket": "your-bucket-name"
}
}
}
}
Now you can create the S3 client from your settings:
import { getSetting } from 'meteor/vulcan:core';
import { createS3Client } from 'meteor/origenstudio:vulcan-files';
// make sure the path of the settings match your own!
const s3Client = createS3Client(
getSetting('amazonAWSS3.mainBucket.client'),
getSetting('amazonAWSS3.mainBucket.cfdomain'),
);
if (Meteor.isClient) {
// is empty object so you can safely retrieve properties from it
console.log(s3Client); //-> {}
}
Once you have your client, you can use it to provide the 3rd party function that createFSCollection
expects:
const MyFilesS3 = createFSCollection({
collectionName: 'MyFilesS3',
uploadTo3rdParty: s3Client.upload,
deleteFrom3rdParty: s3Client.delete,
})
This example uses the Vulcan example-instagram
as base. You find it here.
Features:
- single file
- uses default field's value behavior, so only the file id is stored
- resolves only the file url
- images will be uploaded to
S3
if config is provided