Reputation: 11
I have audio wav file on my server, I wanted to send this file api but I am not able to get how Initialize audio wav file object from path or url.
Here is the code i am using var file = new File("", "1.wav", {type:"audio/x-wav", lastModified: new Date().getTime()});
but it is Initializing file with size 0.
Please help to solve this problem.
Upvotes: 0
Views: 1709
Reputation: 1
You can request the file from server as a Blob
or ArrayBuffer
, then pass the response to File
constructor. Note, the first argument to File
constructor should be an array, not a string
fetch("1.wav")
.then(response => response.blob())
.then(blob => {
let file = new File([blob], "1.wav", {
type:"audio/x-wav", lastModified:new Date().getTime()
});
// do stuff with `file`
})
.catch(err => console.error(err));
Upvotes: 0