Uppy: "Illegal constructor" with Custom plugin

Created on 22 Aug 2019  路  3Comments  路  Source: transloadit/uppy

I keep getting this error message while trying to implement a custom plugin. I have followed the suggestions from the custom compress plugin.

Am I doing something wrong or is there a bug?

Uncaught TypeError: Illegal constructor at new Md5Hash (uppy-md5.js?dd22:6) at Uppy.use (index.js?4bfb:1043)

The illegal constructor points to javascript super(uppy, opts)

const Uppy = require('@uppy/core')
import Md5Hash from './uppy-md5'
const uppy = Uppy({
  id: 'uppy',
  debug: true,
})

uppy.use(Md5Hash, {id: 'Md5Hash'})
const ChunkedFileReader = require('./chunked-reader.js')
const SparkMD5 = require('./sparkMd5.js')

class Md5Hash extends Plugin {
  constructor (uppy, opts) {
    super(uppy, opts)
    this.id = opts.id || 'Md5'
    this.type = 'modifier'

    this.prepareUpload = this.prepareUpload.bind(this)
    this.calcMd5 = this.calcMd5.bind(this)
  }

  calcMd5 (file) {
    this.uppy.log(`[MD5] Calculating Hash: ${file.name}`)
    return new Promise(function (resolve, reject) {
      var spark  = new SparkMD5.ArrayBuffer(),
          reader = new ChunkedFileReader();

      reader.subscribe('chunk', function (e) {
        spark.append(e.chunk);
      });

      reader.subscribe('end', function (e) {
        var rawHash    = spark.end(true);
        var base64Hash = btoa(rawHash);

        resolve(base64Hash);
      });

      reader.readChunks(file);
    })
  }

  prepareUpload (fileIDs) {
    const promises = fileIDs.map((fileID) => {
      const file = this.uppy.getFile(fileID)
      if (file.type.split('/')[0] !== 'image') {
        return
      }
      return this.calcMd5(file.data).then((hash) => {
        this.uppy.setFileMeta(fileID, { MD5Hash: hash })
      })
    })
    return Promise.all(promises)
  }

  install () {
    this.uppy.addPreProcessor(this.prepareUpload)
  }

  uninstall () {
    this.uppy.removePreProcessor(this.prepareUpload)
  }
}

module.exports = Md5Hash

Bug Triage

Most helpful comment

@evanoberholster what was the mistake? I'm stuck at the same line.

All 3 comments

Big mistake on my part. Sorry.

@evanoberholster what was the mistake? I'm stuck at the same line.

@shahimclt
The issue was likely that Plugin was not being imported.
import {Plugin} from '@uppy/core';

Was this page helpful?
0 / 5 - 0 ratings