How to use stream-file-type - 1 common examples

To help you get started, we’ve selected a few stream-file-type examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sozialhelden / accessibility-cloud / both / api / images / server / save-upload-from-stream.js View on Github external
height: 1,
    },
  };

  if (imageId) {
    console.log('Updating previous image upload', attributes);
    Images.update({ _id: imageId }, { $set: attributes });
  } else {
    console.log('Inserting image upload', attributes);
    imageId = Images.insert(attributes);
  }

  // get updated image data
  const image = Images.findOne(imageId);

  const mimeTypeDetector = new FileType();
  const imageSizeDetector = new ImageSize();

  imageStream.pipe(mimeTypeDetector);

  mimeTypeDetector.on('file-type', (fileType) => {
    const unsupportedFileType =
        fileType === null || !allowedMimeTypes.includes(fileType.mime.toLowerCase());
    if (unsupportedFileType) {
      callback(new Meteor.Error(415, `Unsupported file-type detected (${fileType ? fileType.mime : 'unknown'}).`));
      imageStream.emit('error');
    }
    const mismatchedFileType =
        mimeType && fileType && mimeType.toLowerCase() !== fileType.mime.toLowerCase();
    if (mismatchedFileType) {
      callback(new Meteor.Error(415, `File-type (${fileType.mime}) does not match specified mime-type (${mimeType}).`));
      imageStream.emit('error');

stream-file-type

Get the [file type](https://github.com/sindresorhus/file-type) by inspecting a stream.

MIT
Latest version published 3 years ago

Package Health Score

45 / 100
Full package analysis

Popular stream-file-type functions

Similar packages