layerssss / paste.js

read image/text data from clipboard (cross-browser)
http://layerssss.github.io/paste.js/
MIT License
463 stars 94 forks source link

Failed to execute 'readAsDataURL' on 'FileReader': parameter 1 is not of type 'Blob' #41

Closed pkaminski closed 7 years ago

pkaminski commented 7 years ago

A user got this error while using paste.js 0.0.21 within Reviewable:

TypeError: Failed to execute 'readAsDataURL' on 'FileReader': parameter 1 is not of type 'Blob'.
  at readAsDataURL(bower_components/paste.js/paste.js:273:25)
  at apply(bower_components/jquery/dist/jquery.js:4430:8)
  at apply(bower_components/jquery/dist/jquery.js:4116:27)
  at apply(bower_components/raven-js/dist/raven.js:384:28)

This is in Chrome 56.0.2924 on Mac OS X 10.12.2. I don't know what they were trying to paste -- presumably something that's not supported -- but it's probably worth it to stick a try/catch around this line just in case.

layerssss commented 7 years ago

@pkaminski That's highly likely the getAsFile() API is yielding null (that means maybe an invalid image, or a very big image failed to be process by Chrome), since the version is almost the latest.

But sure I'm adding a try catch to make it less exception-ish.

khanhbachnguyen commented 4 years ago

so okay, that's my way, it's worked

const _handleImageChange = (event) => {
    let file = event.target.files[0]
    if (file) {
        let reader = new FileReader()
        reader.onloadend = () => {
            setImagePreviewUrl(reader.result)
        }
        reader.readAsDataURL(file)
    }

}