beek
beek

Reputation: 3750

Javascript File to Blob

I'm recording an audio into an empty file using Cordova Media.

To upload it I need to have the content type on the file.

I'm trying to convert the File into a Blob so I can set the content type, however I'm struggling to convert the File into a blob

state.cordova.localDirectory.getFile(filename,{create:true, exclusive:false},
    f => {
      const options = {
        SampleRate: 16000,
        NumberOfChannels: 1,
      }
      media = new window.Media(f.nativeURL,() =>
        f.file(file => {
          const blob = new Blob(file,{type: 'audio/m4u'}) <--  Trying to convert file into a blob here
          blob.lastModifiedDate = new Date()
          blob.name = filename
          console.log(blob)

          upload(blob,'audio/m4u')
            .then(data=> {console.log(data);store.dispatch(voiceAudioUploaded(sessionId,gameTaskId,data))}, err=> console.log(err))
        }
          , err => console.log('err',err) ))
      media.startRecordWithCompression(options)
    })

Error is `

Failed to construct 'Blob': Iterator getter is not callable.

`

Upvotes: 10

Views: 33699

Answers (1)

Ashraf
Ashraf

Reputation: 2632

Try

const blob = new Blob([file],{type: 'audio/m4u'})

Upvotes: 32

Related Questions