@iwon wrote:
I want to audio record and then upload audio on server
Audio is record and store in local storage but i can’t upload in the serverstartRecord() {
if (this.platform.is(‘ios’)) {
this.fileName = ‘record’ + new Date().getDate() + new Date().getMonth() + new Date().getFullYear() + new Date().getHours() + new Date().getMinutes() + new Date().getSeconds() + ‘.wav’;
this.filePath = this.file.documentsDirectory.replace(/file:///g, ‘’) + this.fileName;
this.audio = this.media.create(this.filePath);
} else if (this.platform.is(‘android’)) {
this.fileName = ‘record’ + new Date().getDate() + new Date().getMonth() + new Date().getFullYear() + new Date().getHours() + new Date().getMinutes() + new Date().getSeconds() + ‘.wav’;
this.filePath = this.file.externalDataDirectory.replace(/file:///g, ‘’) + this.fileName;
this.audio = this.media.create(this.filePath);
}
this.audio.startRecord();
this.recording = true;
}
stopRecord() {
this.audio.stopRecord();alert(JSON.stringify(this.audio)); let data = { filename: this.fileName }; this.audioURI = this.filePath; // alert(); alert(JSON.stringify(data)); this.audioList.push(data); localStorage.setItem("audiolist", JSON.stringify(this.audioList)); this.recording = false; let filePathBase: string = this.filePath; this.base64.encodeFile(filePathBase).then((base64File: string) => { console.log(base64File); alert(base64File); }, (err) => { console.log(err); alert(err); }); this.uploadFile();}
uploadFile() {
let options: FileUploadOptions = {
fileKey: ‘file’,
fileName: this.fileName,
chunkedMode: false,
mimeType: “audio/wav”,
httpMethod: ‘POST’,
headers: { ‘Content-Type’: ‘multipart/form-data’ }}const fileTransfer: FileTransferObject = this.transfer.create();
this.apiUrlAudio = 'http://testing.iwonwebtech.com/school/api/webservices/audio_upload';fileTransfer.upload(this.filePath, encodeURI(this.apiUrlAudio), options)
.then((data) => {
// success
console.log(data);
alert(“suc”);
}, (err) => {
// error
alert(“suc”);
console.log(err);
})}
Posts: 1
Participants: 1