Upload audio file using fileTransfer plugin, using PHP server side

I am trying to upload a audio file, one is .flac and the other.wav file, to a remote server. The file is sent to the server but I get an error back from the server saying that the index of the file was not found. I have double checked that I have the correct fileKey in my ionic FileUploadOptions options but still getting the error

How can I pass the correct index so my server code recognizes the file? I tested using Postman and it works correctly when I input the key name


let options: FileUploadOptions = {
	     fileKey: 'filex',
	     fileName: 'record.flac',
	     mimeType: 'audio/flac',
	     httpMethod : 'post',
	     chunkedMode: false,
	     headers: {'Content-Type': 'multipart/form-data'}

	 this.fileTransfer.upload(this.file.externalDataDirectory+'record.flac', 'http://xxxx.us-east-2.elasticbeanstalk.com/api/upload', options)
	   .then((data) => {
	     // success
	   }, (err) => {
	     // error


         $info = pathinfo($_FILES['filex']['name']);
         $ext = $info['extension']; 
         $newname = 'dog'.'.'.$ext;
         $target = 'uploads/audio/'.$newname;
         $moved = move_uploaded_file( $_FILES['filex']['tmp_name'], $target);

Did you try to var_dump $_FILES? :slight_smile:

Nog only try to dump $_FILES.
First at all check if you receive any data from the call.

Fix error handling in PHP so if there is no data send, return an JSON fault back.
As @mich356c said. Check this first. After that we can help you further.

Yes I tried var_dump and it returns array(0) an empty array

So probably your data is not sending the correct way.

Check if this is not empty:


I have checked in the /data/files folder and it is there, this.file.externalDataDirectory returns correct file path also

Can you give us that information?


console.log(this.file.externalDataDirectory + ' record.flac');

And paste it here.

It is: file:///storage/emulated/0/Android/data/io.ionic.starter/files/record.flac

Ok, clear. it’s filled.

Now let’s check further inside your PHP.
You only checked with a var_dump around your $_FILES?

Did you checked $_POST to?

same thing array(0), empty array as $_FILES

Take a look at this post:

1 Like

This seems to be for ionic 1, not sure if I would have to use encodeURI in the fileTransfer for ionic 2…?

Hi wthijmen,

      I am trying Upload audio file using fileTransfer plugin. Can you please help me onthis

its work fine