Recorderjs icon indicating copy to clipboard operation
Recorderjs copied to clipboard

How to create a File object in Javascript

Open ZengruiWang opened this issue 10 years ago • 6 comments
trafficstars

Hi, I am trying to use recorder.js to a File object in Javascript, I notice that exportWAV will return a blob, then I tried to use it to create the File object like

var file = new File(blob, wavfilename, {
    lastModified: new Date(0), // optional - default = now
    type: "audio/wav" // optional - default = ''
});

But it gives me the error message: Uncaught TypeError: Failed to construct 'File': The 1st argument is neither an array, nor does it have indexed properties. So is there any way to create as a File object? Thank you!

ZengruiWang avatar Nov 13 '15 22:11 ZengruiWang

Why do you want to create a File object? Maybe there's another way to accomplish what you're trying to do.

mattdiamond avatar Nov 13 '15 23:11 mattdiamond

I have to mount the file into Emscripten's virtual file system, is there any way to convert the buffer from float32Array to Uint8Array?

ZengruiWang avatar Nov 13 '15 23:11 ZengruiWang

A bit of a late answer, but just in case anyone else stumbles in here:

var file = new File([blob], wavfilename, {
    lastModified: new Date(0), // optional - default = now
    type: "audio/wav" // optional - default = ''
});

zinas avatar May 16 '16 17:05 zinas

Blob is not defined...

TatoPatato avatar Oct 24 '16 18:10 TatoPatato

Thanks @zinas for this comment. Works very well for me, you saved my life ! :D

psyycker avatar May 29 '17 12:05 psyycker

thumbnail = new File([resp.data], name, { type: 'image/png' }); If I write it in this way then the image file does not appear. If I do not put the resp.data in Array then gives an error Failed to construct 'File': The provided value cannot be converted to a sequence. but the image show up. Strange!!!

faisalakhlaq avatar Jan 12 '23 12:01 faisalakhlaq