将文件上传到文件夹

时间:2019-05-10 08:02:51

标签: angularjs file-upload

我想将文件上传到angularjs的文件夹中。这是我的控制器部分:

const brain = require('brain.js');
const net = new brain.recurrent.LSTMTimeStep();
    net.train([
      {input:[1,2],output:[2]},
      {input:[2,1],output:[2]},  
      {input:[2,3],output:[1]},
      {input:[3,2],output:[1]},
      {input:[1,3],output:[3]}   
    ],{
        log: (error) => console.log(error)
    });

console.log(net.run([3,1]));  

和HTML部分:

var unity = angular.module('unity', ["chart.js"]);

unity.controller("unity", ['$scope', '$http', '$timeout', '$compile', 'fileUpload', function($scope, $http, $timeout, $compile, fileUpload){

    $scope.uploadFile = function() {
       var file = $scope.myFile;
       var uploadUrl = "House/CurrentRoadmap";
       fileUpload.uploadFileToUrl(file, uploadUrl);
    };
}]).directive('fileModel', ['$parse', function ($parse) {
        return {
           restrict: 'A',
           link: function(scope, element, attrs) {
              var model = $parse(attrs.fileModel);
              var modelSetter = model.assign;

              element.bind('change', function() {
                 scope.$apply(function() {
                    modelSetter(scope, element[0].files[0]);
                 });
              });
           }
        };
     }]);
unity.service('fileUpload', ['$http', function ($http) {
   this.uploadFileToUrl = function(file, uploadUrl) {
       console.log(file, uploadUrl);
      var fd = new FormData();
      fd.append('file', file);
      console.log(fd);
      $http.post(uploadUrl, fd, {transformRequest: angular.identity, headers: {'Content-Type': undefined}}).then(function(response){});   
   }
}]);

它工作正常,没有给我任何错误,但是文件不在文件夹中。有没有办法检查为什么文件没有上传到文件夹?

0 个答案:

没有答案