使用ionic将文件上传到服务器

时间:2016-06-28 16:22:08

标签: angularjs ionic-framework

我正在使用离子构建移动应用。其中一个用例是让用户浏览文件并将其上传到后端服务器(公开休息服务)。

在用户界面上,我使用的是html文件标记

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

这将打开文件浏览器以选择文件。然后在控制器中,我正在执行以下操作

.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
  });
});

问题是我无法获得对所选文件的引用。有人可以请帮助实现这一目标的步骤。谢谢!

0 个答案:

没有答案