2

I am building a mobile app using ionic. One of the usecase is to let the user browse a file and upload it to the backend server (which exposes a rest service).

On the UI, I am using the html file tag

<input type="file" ng-select="uploadFile($files)" multiple>

This opens a file browser to select a file. Then in the controller, I am doing the following

.controller('UploadDocCtrl', function ($scope, $cordovaFileTransfer) {

$scope.uploadFile = function(files) {
  console.log("selected file "+files);
 // hard coded file path "/android_asset/www/img/ionic.pdf" to be replaced with the user selected file
  $cordovaFileTransfer.upload(restServiceEndpoint, "/android_asset/www/img/ionic.pdf", properties).then(function(result) {
    console.log("SUCCESS: " + JSON.stringify(result.response));
  }, function(err) {
    console.log("ERROR: " + JSON.stringify(err));
  }, function (progress) {
    // constant progress updates
  });
});

The problem is that I am not able to get a reference to the selected file. Can someone please help with the steps to achieve this. Thanks!

kayasa
  • 2,055
  • 8
  • 37
  • 63
  • check this question : http://stackoverflow.com/questions/17063000/ng-model-for-input-type-file – Prashant Ghimire Jun 28 '16 at 20:31
  • chek this Question : https://www.thepolyglotdeveloper.com/2015/01/upload-files-remote-server-using-ionic-framework/ – Mohan Gopi Jun 29 '16 at 05:10
  • Hi Mohan Gopi, I have seen this example and also tried following it. However, there is a problem with this example. It has a hard coded file path and file name - "/android_asset/www/img/ionic.png". In my case I don't know what file the user will select and at what path it will reside on the mobile device. So, I need a way to get a handle to the file object and get the file name and path dynamically. Without that information this example is not is much use. Unfortunately, the example doesn't talk about that at all. – kayasa Jun 30 '16 at 07:08

0 Answers0