I've a portal in which I'm recording user audio and I am getting a blob URL and now I want to store this blob url as a file in my database. Can anyone help me with this. This is my js code
$('#upload-read-aloud').on('submit',function(e){
e.preventDefault();
$.ajax({
type : 'GET',
cache : false,
data : {audioUrl:audioUrl},
url : '../upload-read-aloud-test',
success:function(response){
alert(response)
}
})
})
And this is my controller code
$url = $req->audioUrl;
$upload_dir = public_path()."/assets/";
$audio= $url;
$audio= str_replace('data:audio/wav;base64,', '', $audio);
$audio = str_replace(' ', '+', $audio);
$data = base64_decode($audio);
$file = $upload_dir . time() . ".wav";
$success = file_put_contents($file, $data);
echo $success ? $file : 'Unable to save the file.';
audioUrl is the Blob url which I'm passing in my route. The file is saving into the database but the file is empty.