muxinc / upchunk

Uploads Chunks! Takes big files, splits them up, then uploads each one with care (and PUT requests).
MIT License
345 stars 46 forks source link

TypeError: Cannot read property 'createUpload' of undefined #11

Closed skjo0c closed 5 years ago

skjo0c commented 5 years ago

I am trying to use upchunk to upload video in mux with direct uploads, but shows following error: TypeError: Cannot read property 'createUpload' of undefined. I am trying to upload with react-dropzone and following is a part of my code:

import UpChunk from '@mux/upchunk'

 <Dropzone
              className={classes.dropzone}
              maxSize={MAX_SIZE}
              accept="video/*"
              onDrop={this.uploadHandler}
            >...</Dropzone>

uploadHandler = (accepted) => {
    accepted.forEach((file) => {
      // console.log(file)
      const getUploadUrl = () => {
        fetch('/video-upload').then((res) =>
          res.ok
            ? res.text()
            : console.log(new Error('Error getting an upload URL :(')),
        )
      }

      console.log(getUploadUrl, 'getUploadUrl')

      const upload = UpChunk.createUpload({
        endpoint: '/video-upload',
        file,
        chunkSize: 5120, // Uploads the file in ~5mb chunks
      })

      // subscribe to events
      upload.on('error', (err) => {
        console.error('💥 🙀', err.detail)
      })

      upload.on('progress', (progress) => {
        console.log(`So far we've uploaded ${progress.detail}% of this file.`)
      })

      upload.on('success', () => {
        console.log("Wrap it up, we're done here. 👋")
      })
    })
  }
mmcc commented 5 years ago

Gah this question was answered in a different conversation and I forgot to follow up here.

I'll update the documentation, but this should be import * as UpChunk from '@mux/upchunk';.