ng-file-upload没有达到正确的端点

时间:2017-01-25 22:49:03

标签: angularjs meanjs

我正在使用MEANJS。我在客户端使用ng-file-upload上传文件。问题是在我为上传定义的url中,没有参数,但是当命中端点时,它会调用它认为其中有参数的函数。这个upload正在创建新的activity activities与默认articles

相同的结构)

控制器:

function save(isValid) {
    Upload.upload({
        url: 'api/activities/gpxData', // no optional parameter ':activityId'
        data: {
            file: $scope.gpxData
        }
        }).then(function(resp) {
            console.log(resp);
        }, function(resp) {
            console.log(resp)
        }, function(evt) {

        }
    });     
}

这些都是我route定义的:

app.route('/api/activities').all(activitiesPolicy.isAllowed)
    .get(activities.list)
    .post(activities.create);

app.route('/api/:userId/activities').all(activitiesPolicy.isAllowed)
    .get(activities.usersActivities)
    .post(activities.create);

app.route('/api/activities/:activityId').all(activitiesPolicy.isAllowed)
    .get(activities.read)
    .put(activities.update)
    .delete(activities.delete);

app.route('/api/:userId/activities/:activityId').all(activitiesPolicy.isAllowed)
    .get(activities.read)
    .put(activities.update)
    .delete(activities.delete);

app.route('/api/activities/gpxData').all(activitiesPolicy.isAllowed)
    .post(activities.uploadGpx);

// Finish by binding the Activity middleware
app.param('activityId', activities.activityByID);

即使在activityId中没有传递可选参数url,也会调用函数activities.activityByID,这是:

exports.activityByID = function (req, res, next, id) {
    if (!mongoose.Types.ObjectId.isValid(id)) {
        return res.status(400).send({
            message: 'Activity is invalid'
        });
    }
};

此外,中传递id(正在创建id的{​​{1}} 但我不知道从哪里来的它不是有效的activity,因为它尚未输入mongo。

1 个答案:

答案 0 :(得分:0)

这是由快速代码中的路由排序引起的。因为/ api / activities / gpxData适合模式/ api / activities /:activityId。 路由在第一个匹配规则上停止并执行。这是各种技术中路由的标准实现。

移动

df[df[:col1] .== x,:col2]

之前

app.route('/api/activities/gpxData').all(activitiesPolicy.isAllowed)
   .post(activities.uploadGpx);

然后尝试运行。