Recorderjs
Recorderjs copied to clipboard
How to create a File object in Javascript
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!
Why do you want to create a File object? Maybe there's another way to accomplish what you're trying to do.
I have to mount the file into Emscripten's virtual file system, is there any way to convert the buffer from float32Array to Uint8Array?
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 = ''
});
Blob is not defined...
Thanks @zinas for this comment. Works very well for me, you saved my life ! :D
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!!!