Upload image to server

Can any one know how to upload a picture to php server
i need source code example ionic and php as well

You can use the File Transfer plugin.

Not to do your job for you, but in the past I’ve done base64 strings and posted them to a backend server in a json payload.

You can then convert the string to a file on the server itself, or store it as a string on your db

yes i have used file transfer plugin but at server end im getting null

yes i have tried to store base64 string but im getting request entitiy is too large error
thats y i have asked sample code

Are you posting or ‘getting’?

im sending the data by posting

Can you share the code you are using to post the file?

let body = new FormData();

var result;

return new Promise(resolve=>{

       result = data;

       result = error;

here is the code

please help me im stuck with this since two days

You are not using FileTransfer. Use the following code:

import { FileTransfer, FileUploadOptions, FileTransferObject } from '@ionic-native/file-transfer';


constructor(private transfer: FileTransfer) {


const fileTransfer: FileTransferObject = this.transfer.create();

let options: FileUploadOptions = {
  fileKey: "photo",
  fileName: "filename.jpg",
  chunkedMode: false,
  params : {
      "username": username,
      "title": activity[“Activity”],
      // the rest of your form fields go here, except photo

fileTransfer.upload(photo, 'https://someserver/testphp.php', options)
.then((data) => {
  console.log('uploaded successfully');
}, (err) => {
  console.log('upload failed!');

thank you ill try this method

I am also facing same problem. I am able to load photo to local directory but not able to load to server, So that when i am refreshing profile page the photo again moving to default image.
I have only api’s endpoint and parameter. can anyone tell me