I record an audio from microphone and I need to send it to server with a POST form.
I am able to record and to have the blob object, but I do not know how to send.
I tried to transform the blob to ArrayBuffer and set an hidden field with the value, but I am not sure if it is the right way.
This is the js code to get the blob, transform to ArrayBuffer and set to the hidden field:
var arrayBuffer;
var fileReader = new FileReader();
fileReader.onload = function(event) {
arrayBuffer = event.target.result;
jQuery('hidden_field').val(arrayBuffer);
};
fileReader.readAsArrayBuffer(blobObject);
After that I simply send the form normally with a submit button.
On the server, If I do dd command to the request object, this is what I get:
array:2 [▼
"_token" => "8HcKsoGblW9lEPVY0JYrFDbDAajdb63xdSQC3r5E"
"hidden_field" => "[object ArrayBuffer]"
]
I do not know if it is correct or not.
If it is correct, how can I handle it?
UPDATED
I solved sending the blob in an hidden field as a base64 string, with this code:
var fileReader = new FileReader();
fileReader.onload = function(event) {
jQuery('#hidden').val(fileReader.result.substr(fileReader.result.indexOf(',')+1));
};
fileReader.readAsDataURL(s);