Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

`

like image 746
beek Avatar asked Nov 30 '22 21:11

beek


1 Answers

Try

const blob = new Blob([file],{type: 'audio/m4u'})
like image 137
Ashraf Avatar answered Dec 04 '22 11:12

Ashraf