使用$ http在AngularJs中复制PUT请求

时间:2015-06-10 18:23:22

标签: angularjs

我正在尝试使用PUT方法在AngularJs中创建新目录后将文件上传到ftp。当我的第一个请求处理的时候比我的第一个请求仍在上传文件时我可以再次看到重复的PUT请求,并且我的目录错误已经存在。

PUT user/audio/deliverftp1  // First request
uploaded Audio >>1 >>1572528
uploaded Audio >>1 >>1637949
uploaded Audio >>1 >>1703388
uploaded Audio >>1 >>1768865
uploaded Audio >>1 >>1834167
PUT user/audio/deliverftp1 - - ms - -   
               // as soon as this line execute I get ERROR
uploaded Audio >>1 >>1899552

这是我的部分代码

sync.map(req.body.tracks, function(track, callback) {
    var data = '';
    var filename = '';
    var readableAudioStream = fs.createReadStream(track.trackpath.track_path);
    c.put(readableAudioStream,track.filename, function(err) {
      if (err) {
        return callback(err);
      }
      callback(null);
    });
    readableAudioStream.on('data', function(chunk) {
      data += chunk;
      console.log('uploaded Audio >>'+track.track_no+' >>'+data.length);
    });
}, function(err, results) {
  console.log('audio error');
  console.log(err);
  done(err);
});

角度控制器:

  $scope.deliverAudio =  function(){
        var ftp1  = albumpackages.delivertoFpt1($rootScope.audio);
        var ftp2  = albumpackages.delivertoFtp2($rootScope.audio);
                Q.allSettled([ftp1,ftp2])
                .then(function (results) {
                    results.forEach(function (result) {
                                console.log('inside result');
                                console.log(result);
                        if (result.state === "fulfilled") {
                            var value = result.value;
                        } else {
                            var reason = result.reason;
                        }
                    });
                });
      }

Angular Service:

angular.module('albumpackages').factory('albumpackages', ['$http',
    function($http) {
        return{
            delivertoFtp1 : function(audio){
                return $http.put('user/audio/deliverftp1',audio);
            },
            delivertoFtp2 : function(audio){
                return $http.put('user/audio/deliverftp2',audio);
            }
      }

0 个答案:

没有答案