0

How to upload pdf file on server using $cordovaFileTransfer plugin. I have a below input field

<input type="file"  onchange="angular.element(this).scope().fileNameChanged(this)">

How to get pathForFile here ?

$cordovaFileTransfer.upload(url, pathForFile, options).then(function(result) {
 alert('Your image has been successfully uploaded');
},
function(erro)
{
alert("Failed uploading image on server")
});
sam
  • 688
  • 1
  • 12
  • 35
  • check documentation http://ngcordova.com/docs/plugins/fileTransfer/ they have mentioned about targetPath 'var targetPath = cordova.file.documentsDirectory + "testImage.png";' – Manish Rane Feb 06 '17 at 07:18
  • But I dont have to uplaod "testImage.png" . User browse the file on the device and I want to get the path of selected file by user – sam Feb 06 '17 at 07:21
  • "testImage.png" is the example in documentation and it means which image your are uploading. You can try ---- var image = document.getElementById('tempImage'); image.src = imageData; var server = "http://yourdomain.com/upload.php", pathForFile = imageData; ---- Ref. http://stackoverflow.com/questions/30534820/ionic-app-image-upload-from-camera-photo-library – Manish Rane Feb 06 '17 at 08:41

1 Answers1

0

First add cordova-plugin-file plugin to your project. according to your targeting platform then you can decide where should save file before updating.

if you choose cordova.file.externalRootDirectory as file storage path then pathForFile will be

var pathForFile= cordova.file.externalRootDirectory + "UploadMe.pdf";
Uditha Prasad
  • 695
  • 5
  • 13