在更新MEAN堆栈中的集合时遇到困难

时间:2017-11-20 17:34:32

标签: angularjs node.js mean-stack

我正在尝试使用一组字段的现有集合。

  1. 我正在将数据保存到一个集合中。
  2. 后来我想用图像数据更新集合,所以我尝试更新现有集合。
  3. 但是我在 Angular Controller端

    获得了以下异常:

    Possibly unhandled rejection: {
        "data":"<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n<meta charset=\"utf-8\">\n<title>Error</title>\n</head>\n<body>\n<pre>Cannot POST /image/upload</pre>\n</body>\n</html>\n",
        "status":404,
        "config":{
            "method":"POST",
            "transformResponse":[null],
            "jsonpCallbackParam":"callback",
            "url":"/image/upload",
            "headers":{"Accept":"application/json, text/plain, */*"},
            "data":{
                "model":{"title":"hello"},
                "files":[{}]
            }
        },
        "statusText":"Not Found"
    }
    

    角色代码:

    $http({
      method: 'PUT',
      url: properties.imageUpload,
      headers: { 'Content-Type': undefined },
      transformRequest: function(data) {
        var formData = new FormData();
        formData.append("proId", $scope.pid);
        formData.append('model', angular.toJson(data.model));
        for (var i = 0; i < data.files.length; i++) {
          formData.append('file', data.files[i]);
          $scope.uploadedFiles.push(data.files[i]);
        }
        console.log('Sending File size :' + data.files.length);
        //formData.append('file', data.files[0]);
        return formData;
      },
      data: { model: { title: 'hello' }, files: $scope.files }
    
    }).then(function(res) {
      $scope.selectedFiles = "/public/images/" + res.data.imagePaths[0];
      //      console.log(res.data.imagePaths[0]);
    });
    



    $scope.addProducts = function () {
              var product = $scope.product;
              $http.post('/products/create', $scope.product).then(function (res) {
                console.log(res.data._id);
                $scope.upload(res.data._id);//this contains put request.
              });
            }
    

    请帮忙。

0 个答案:

没有答案
相关问题