An easy to use middleware to create photo galleries on the local ( to the server ) disk. This can be used with ajax techniques and without.
Install with npm install express-galleria --save
Initialize inside of a routes file:
const galleria = require('express-galleria');
const gallery = galleria(); // To initialize
galleria takes an optional options object with the following:
This is the absolute path to the root of the gallery. This should only be changed if the node application is launched from some place other than the root of the application.
This is the relative path to the public files. This should match the express.static()
directory listed below.
// Main app.js
app.use(express.static(path.join(__dirname, 'public')));
This is the form field that is sent via POST request that contains the images, it can accept multiple images at a time.
The width of the full-size images, the height will scale to maintain aspect ratio.
The width of the thumbnail image, the height will scale to maintain aspect ratio.
After initializing the gallery object, you will need to set the proper routes up:
All methods here should be called with {ajax: true}
if not used as middleware. Only when {ajax: true}
is passed, next()
will be called.
Handles the upload, to be used with req.params.category
usage:
router.post('/:category', gallery.upload({ ajax: true }));
This will get a list of all categories.
usage:
router.get('/', gallery.getIndex(), galleryController.index);
This route will get all the images from the specified category, to be used with req.params.category
usage:
router.get('/:category', gallery.getImagesFromCategory({ ajax: true }));
Removes a category from the disk, including all images in that category, to be used with req.params.category
usage:
router.post('/:category/delete', gallery.removeCategory({ ajax: true }));
Removes an image from a specified category, to be used with req.params.category
, and req.params.image
where image
is the ID of the image.
usage:
router.post('/:category/:image/delete', gallery.removeImage({ ajax: true }));