Skip to content
This repository has been archived by the owner on Nov 13, 2022. It is now read-only.

LogicamenteInfo/mongoose-uploaded-file

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mongoose-uploaded-file

This is a mongoose SchemaType to store path of saved files.

What it does

  • Save a String contaning the path to a file saved at device disk
  • Validates if the file exists before saving at database

Installation

$ npm i -S @logicamente.info/mongoose-uploaded-file # NPM users
$ yarn add @logicamente.info/mongoose-uploaded-file # YARN users

How to use

const mongoose = require('mongoose');
const Schema = mongoose.Schema;
// Add the UploadedFile SchemaType to mongoose
require('@logicamente.info/mongoose-uploaded-file').loadType(mongoose);
const UploadedFile = mongoose.Types.UploadedFile;

// If you haven't declared the const UploadedFile
// you can use 'mongoose.Types.UploadedFile'
const ProductSchema = Schema({
  photo: { type: UploadedFile }
});

const Product = mongoose.model('Product', ProductSchema);

const p = new Product();
p.photo = '/upload/photo.jpg'

Schema options

It accepts all properties from mongoose String SchemaType.

// This will transform the path into lowercase, then remove blank space
// at start and end, then validates if the file exists
var ProductSchema = Schema({
  photo: { type: UploadedFile, required: true, lowercase: true, trim: true }
});

Testing

At root of this project, run npm test

About

Adds the SchemaType 'UploadedFile' to mongoose in order to verify if file exists.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published