Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const BlobService = require('feathers-blob');
- const fs = require('fs-blob-store');
- const multer = require('multer');
- const multipartMiddleware = multer();
- const { getBase64DataURI } = require('dauria');
- const blobStorage = fs(__dirname + '/uploads');
- module.exports = function (app) {
- app.use('/uploads',
- multipartMiddleware.single('file'),
- function(req,res,next){
- req.feathers.file = req.file;
- next();
- },
- BlobService({
- Model: blobStorage
- })
- );
- // Get our initialized service so that we can register hooks and filters
- const blobService = app.service('uploads');
- //service.hooks(hooks);
- blobService.hooks({
- before:{
- create: [
- function(context) {
- if (!context.data.uri && context.params.file){
- const file = context.params.file;
- const uri = getBase64DataURI(file.buffer, file.mimetype);
- context.data = {uri: uri};
- }
- }
- ]
- }
- });
- const blob = {
- uri: getBase64DataURI(new Buffer('hello world'), 'text/plain')
- };
- blobService.create(blob).then(function (result) {
- console.log('Stored blob with id', result.id);
- }).catch(err => {
- console.error(err);
- });
- };
Add Comment
Please, Sign In to add comment