🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

mongofiles

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongofiles

A package to save files name into mongodb easily

latest
npmnpm
Version
1.0.3
Version published
Weekly downloads
4
33.33%
Maintainers
1
Weekly downloads
 
Created
Source

mongofiles

A package to easily save filenames to MongoDB

Installation

Install mongofiles with npm

  npm install mongofiles

Tech Stack

Server: Node, Express

Usage/Examples

const Blog = require("../models/blog");
const mongofiles = require("mongofiles"); //importing mongofiles

exports.add = (req, res, next) => {
  var {
    images,
    featuredimage
  } = req.body;  

//for more than one files, it return array of filenames
  images = mongofiles.manyfile( req.files.images,  "images", "filename"  );
 
//for only one file it returns a string  
  featuredimage = mongofiles.onefile(req.files.featuredimage, featuredimage, "filename");

  let newBlog = new Blog({
    images,
    featuredimage
  });

  newBlog.save((err, data) => {
    if (err) {
      return res.status(400).json({
        error: err,
      });
      console.log(err);
    } else {
      res.json(data);
      console.log(data);
    }
  });
};

API Reference

//return a array of filenames
  mongofiles.manyfiles(req.files.<name>, "name" , "Option", custom )

//return a string of single file
  mongofiles.onefile(req.files.<name>, "name" , "Option", custom ) 

Select any for options Required Options are same for manyfiles and onefile

OptionTypeDescription
originalstringReturns original filename
filenamestringReturns filename uploaded with the name
customfilenamestringReturns filename uploaded file with the custom string or number name
customoriginalnamestringReturns original uploaded file with the custom string or number name

Custom is only mandatory if you go for customfilename and customoriginalname

You can write string or number there or pass Date.now()

Authors

  • @Amanp30

Keywords

files

FAQs

Package last updated on 06 Nov 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts