Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to create a File object in Javascript #138

Open
ZengruiWang opened this issue Nov 13, 2015 · 6 comments
Open

How to create a File object in Javascript #138

ZengruiWang opened this issue Nov 13, 2015 · 6 comments

Comments

@ZengruiWang
Copy link

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!

@mattdiamond
Copy link
Owner

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

@ZengruiWang
Copy link
Author

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

@zinas
Copy link

zinas commented May 16, 2016

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 = ''
});

@TatoPatato
Copy link

Blob is not defined...

@psyycker
Copy link

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

@faisalakhlaq
Copy link

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!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants