Tabnine Logo For Javascript
mime-types
Code IndexAdd Tabnine to your IDE (free)

How to use mime-types

Best JavaScript code snippets using mime-types(Showing top 15 results out of 315)

origin: vss-devel/zimmer

function mimeFromPath ( path ) {
  var mType = mimeTypes.lookup( path )
  if ( mType == null ) {
    console.error( 'No mime type found', path )
  }
  return mType
}
origin: lbryio/spee.ch

generated_extension() {
  logger.debug('trying to generate extension', this.content_type);
  if (customFileExtensions.hasOwnProperty(this.content_type)) {
   return customFileExtensions[this.content_type];
  } else {
   return mime.extension(this.content_type) ? mime.extension(this.content_type) : 'jpg';
  }
 }
origin: nodeschool/karachi

multer.diskStorage({
 filename: (req, file, cb) => {
  const ext = mimeType.extension(file.mimetype)
  cb(null, `file-${Date.now()}.${ext}`)
 },
 destination: (req, file, cb) => {
  cb(null, uploadDir)
 }
})
origin: jirengu/node-server

function Mime(req, res, next){
 var pathObj = url.parse(req.url, true)
 var mimeType = mime.lookup(pathObj.pathname)
 console.log(mimeType)

 res.setHeader('content-type', mimeType)
 next()
}
origin: radhey113/node-with-express-and-swagger-docker

FS.readFile(fileObj.path, (err, fileData) => {
       s3.putObject({
                 Bucket: CONFIG.awsConfig.bucket,
         Key: fileName,
         Body: fileData,
         ContentType: mime.lookup(fileName)
                }, (err, data) => {
                err ? reject(err): resolve(data);
        });
     });
origin: gram-js/gramjs

function isVideo(file) {
  return (mime.lookup(file) || '').startsWith('video/')
}
origin: egodigital/vscode-powertools

private getCharSet() {
    let charset: false | string = mimeTypes.charset(
      this.getContentType()
    );
    if (false === charset) {
      charset = 'ascii';
    }
    charset = charset.toLowerCase()
      .split('-')
      .join('')
      .trim();

    return charset;
  }
origin: ThalKod/discord-clone

multer({
  storage: multer.diskStorage({
    destination: path.join(__dirname, "../public/files/image"),
    filename: (req, file, cb)=>{
      crypto.pseudoRandomBytes(4, (err, raw)=>{
        const mimeType = mime.lookup(file.originalname);
        // throw away any extension if provided
        const nameSplit = file.originalname.split(".").slice(0, -1);
        // nameSplit.pop();

        // replace all white spaces with - for safe file name on different filesystem
        const name = nameSplit.join(".").replace(/\s/g, "-");
        cb(null, raw.toString("hex") + name + "." + mime.extension(mimeType));
      });
    },
  }),
})
origin: vss-devel/zimmer

basePath () {
    let name
    const purl = urlconv.parse( this.url )
    if ( purl.query && purl.query.includes( '=' ) && this.mimeType ) {
      const pathp = osPath.parse( purl.path )
      const ext = '.' + mimeTypes.extension( this.mimeType )
      name = pathp.base + ext
    } else {
      const pathp = osPath.parse( purl.pathname )
      name = pathp.name + pathp.ext.toLowerCase()
    }
    return sanitizeFN( decodeURIComponent( name ))
  }
origin: vidaxl-com/cowlog

fileInfoServices.service('type', function (path) {
  let type = String(mime.lookup(path.toString()))

  return type
 }, 'path')
origin: RyanAfrish7/thumbsupply

_fetchThumbnailSupplier(file, options) {
    const mime = options.mimetype || mimetypes.lookup(file);
    let Supplier;

    if (!mime) {
      throw new E.UnknownFiletypeError(file, undefined, "Unable to probe mimetype from filename");
    }

    if (this._thumbSuppliers.has(mime)) {
      Supplier = this._thumbSuppliers.get(mime);
    } else if (this._thumbSuppliers.has(mime.replace(/(.+\/)(.+)/, "$1*"))) {
      // regex to replace application/json -> application/*
      Supplier = this._thumbSuppliers.get(mime.replace(/(.+\/)(.+)/, "$1*"));
    } else {
      throw new E.UnknownFiletypeError(file, mime, "FileType has no associated ThumbnailSupplier");
    }

    return new Supplier(options);
  }
origin: gram-js/gramjs

function isAudio(file) {
  return (mime.lookup(file) || '').startsWith('audio/')
}
origin: divy-work/arcadia

multer({
  storage: multer.diskStorage({
    destination: path.join(__dirname, "../public/files/image"),
    filename: (req, file, cb)=>{
      crypto.pseudoRandomBytes(4, (err, raw)=>{
        const mimeType = mime.lookup(file.originalname);
        // throw away any extension if provided
        const nameSplit = file.originalname.split(".").slice(0, -1);
        // nameSplit.pop();

        // replace all white spaces with - for safe file name on different filesystem
        const name = nameSplit.join(".").replace(/\s/g, "-");
        cb(null, raw.toString("hex") + name + "." + mime.extension(mimeType));
      });
    },
  }),
})
origin: ThalKod/DropIt

multer({
  storage: multer.diskStorage({
    destination: path.join(__dirname, 'files/'),
    filename: function (req, file, cb) {
      crypto.pseudoRandomBytes(4, function (err, raw) {
        const mime_type = mime.lookup(file.originalname);

        // throw away any extension if provided
        const nameSplit = file.originalname.split(".").slice(0,-1);
        //nameSplit.pop();

        // replace all white spaces with - for safe file name on different filesystem 
        const name = nameSplit.join(".").replace(/\s/g,'-');
        cb(null, raw.toString('hex') + name + '.' + mime.extension(mime_type));
      });
    }
  })
})
origin: divy-work/arcadia

multer({
  storage: multer.diskStorage({
    destination: path.join(__dirname, "../public/files/image"),
    filename: (req, file, cb)=>{
      crypto.pseudoRandomBytes(4, (err, raw)=>{
        const mimeType = mime.lookup(file.originalname);
        // throw away any extension if provided
        const nameSplit = file.originalname.split(".").slice(0, -1);
        // nameSplit.pop();

        // replace all white spaces with - for safe file name on different filesystem
        const name = nameSplit.join(".").replace(/\s/g, "-");
        cb(null, raw.toString("hex") + name + "." + mime.extension(mimeType));
      });
    },
  }),
})
mime-types(npm)

JSDoc

The ultimate javascript content-type utility.

Most used mime-types functions

  • lookup
  • extension
  • charset
  • contentType
  • getType

Popular in JavaScript

  • bluebird
    Full featured Promises/A+ implementation with exceptionally good performance
  • colors
    get colors in your node.js console
  • crypto
  • body-parser
    Node.js body parsing middleware
  • mkdirp
    Recursively mkdir, like `mkdir -p`
  • webpack
    Packs CommonJs/AMD modules for the browser. Allows to split your codebase into multiple bundles, which can be loaded on demand. Support loaders to preprocess files, i.e. json, jsx, es7, css, less, ... and your custom stuff.
  • through2
    A tiny wrapper around Node.js streams.Transform (Streams2/3) to avoid explicit subclassing noise
  • handlebars
    Handlebars provides the power necessary to let you build semantic templates effectively with no frustration
  • commander
    the complete solution for node.js command-line programs
  • Best IntelliJ plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJavascript Code Index
Get Tabnine for your IDE now