How to get audio file after recording (cordova-plugin-media)

I’m using the cordova-plugin-media ( to let users record their voice.

The plugin defines a media object:

my_media = new Media(src, onSuccess, onError)

And it comes with a bunch of API methods like startRecord() and stopRecord() that can operate on the media object. Once the user has finished recording, I can call the Play() method on the media object to playback the recording. All of this works fine for me, but I am not sure how to grab the actual audio file so I can post it ($ to my server. Any help is appreciated.

Thank you.

Take a look at this thread about deleting a media file, it discusses how to locate a file after cordovaMedia has finished recording it. It might help:

Do you include the ‘document://’ prefix on your source media file? That will assist a lot in the device placing the media file in the correct spot.

OK so basically cordova-plugin-media creates a file somewhere in the device’s storage when recording (media.startRecord()), and I just need to use Cordova’s file handling plugin to get a hold of that file, right?

Yes - that is pretty much exactly what happens.

Not sure what platform you are using, but iOS tends to create the media files in the /tmp folder by default. Using the ‘documents://’ prefix on the file name make the Media plugin create the file in the AppData/Documents folder, which is more persistent.

Where you store the file depends on whether you want to keep it etc. But the real trick is locating the file afterwards so you can delete/move/upload it etc. iOS and Android have small differences in where they store the file, and hence how you locate it.

Thank you. I am on Android.

While we are at it, let me ask…once I get a hold of the file, is it as simple as just doing $, file)? Do I need to do anything else, like encoding/content type/etc?

Hi I am also facing same problem
I am building app for android phone
where I am recording users email and dob and i want that two audio files to send to my server

on button click I am recording users voice but it is storing on sdcard which I don’t want I want to use phone storage

here is my code

var myMedia;
$scope.captureEmail = function () {
myMedia = new Media(“myemail.mp3”);

$scope.stopRecord = function () {        

$scope.playEmail = function () {

    var myMedia = new Media("/sdcard/myemail.mp3");;

Hello prabhu_108 Where you finally able to do this? if yes please can you share thanks.

Hi nice link could, i tried it startrecord works well but i could not make a playback, cam u tell me how to change file name or to get the path of audio file that is been created wit cordova-media-plugin

hi, how to use cordova.file.documentsDirectory on ionic 2

Something new for ionic 2?

guys any solution on this? I can record file and play it. I want to upload to firebase. I think i need to convert it to base64 or into BLob first.

This is pretty old but you can use the File plugin and the [readAsDataURL] which will convert your file to base64. (