Reputation: 184
I am using RecordRTC to record the voice and trying to send the recorded voice to server. Below is the code to store the blob and file name.
public uploadToServer(recordRTC, callback) {
let blob = this.recordRTC instanceof Blob ? this.recordRTC : this.recordRTC.blob;
let fileType = blob.type.split('/')[0] || 'audio';
let fileName = (Math.random() * 1000).toString().replace('.', '');
if (fileType === 'audio') {
fileName += '.' + (!!navigator.mozGetUserMedia ? 'ogg' : 'wav');
} else {
fileName += '.webm';
}
// create FormData
var formData: FormData = new FormData();
console.log(fileName);
console.log(blob);
formData.append(fileType + '-filename', fileName);
formData.append(fileType + '-blob', blob);
console.log(formData);
}
I have console the filename and blob file separately. it is showing. but when I am appending the blob and filename in formData, it is showing blank.
Please help me.
Upvotes: 1
Views: 5320
Reputation: 1139
you can use this to append blob data.
form.append("blob",blob, filename);
to console log. use this.
for (var pair of formData.entries()) {
console.log(pair[0]+ ', ' + pair[1]);
}
The console log should work if the data has appended.
Upvotes: 1
Reputation: 2592
In console.log(formData)
is always showing null. Insted of that you can use formData.get('PassKeyHere')
to get data.
Upvotes: 1