使用ng-file-upload上传数据和文件

时间:2016-10-14 08:03:02

标签: ng-file-upload

我是棱角分明的新人。我搜索了很多,但没有找到通过ng-file-upload的 Upload.upload()获取数据的方法。虽然我的文件使用muter

上传到目标文件夹

这是我的受控功能,在视图中上传点击时调用。

$scope.doUpload = function() {
Upload.upload({
      url: '/api/upload/',
      data: {'sabhaDetails': sabhaDetails},
      file: sabhaFile,
      fileName: sabhaDetails.sabha_video_name
    });
}

在我的路线中,我有:

/ annotator page. (http://localhost:1337/api/upload)
annotationRouter.route('/upload')
  .post(function(req, res) {
    **console.log(req.data);**
    upload(req, res, function(err) {
      if(err) {
        res.json({ error_code:1, err_desc:err });
        return;
      }
      res.json({ error_code:0, err_desc:null });
    })
  });

但我的req.data未定义。有什么不对。如何通过上传获取发送数据?

2 个答案:

答案 0 :(得分:1)

如果您使用的是Node.js,除了文件之外的所有表单数据都应该在请求对象的正文键下分配

在这种情况下,我认为它应该是req.body.data

我的工作方式是在数据键上发送所有内容:

series: [{
        name: 'Country',
        joinBy: 'hc-key',
        color :'red',
        data: data.slice(),
        dataLabels: {
            enabled: true,
            color: '#FFFFFF',
            formatter: function () {
                if (this.point.value) {
                    return this.point.name;
                }
            }
        }
    }, {
        type: 'mapbubble',
      data: data,
      joinBy: 'hc-key',
      minSize: 30,
      maxSize: 40,
      dataLabels: {
        enabled: true,
        format: '{point.name}'
      }
    }]

然后我可以读作:

Upload.upload({
      url: '/api/works/new',
      method: 'POST',
      data: {content: angular.toJson(controller.work), file: controller.thumb}
  }).

,文件为:

req.body.content

答案 1 :(得分:0)

您正在从ngf收到multipart/form-data

我不知道您使用的服务器,但我认为您应该检查req.form而不是req.data或其他内容。

或者,您可以使用一些外部中间件,例如this

相关问题