小编san*_*h_p的帖子

帆js - 水线ORM限制或分组后排序?

我在sails.js上使用Waterline ORM.limit并且sort在使用时不起作用groupby,但在不进行任何分组时工作正常.

例如

Model.find({
    groupBy:['term'],
    sum:['count'],
    limit:20,
    sort :'count DESC'}).exec(function(error,response){
        if(error) res.json(error);
        res.json(response);
    });
Run Code Online (Sandbox Code Playgroud)

sails.js waterline sails-mongo

8
推荐指数
1
解决办法
9182
查看次数

Node js通过jquery发送post请求表单数据错误

我想通过 jQuery 请求发送文件post。我的 node.js 将读取该文件并插入data到 Mongodb 中。

这是我的 node.js 函数:

upload: function(req, res){
    var FileName;
      req.file('myFile').upload(function(err,files){
      var i = 1;
        if(err) return res.serverError(err);
      FileName = files[0].filename; ......
Run Code Online (Sandbox Code Playgroud)

post如果直接从html以下位置发送请求,上述函数可以正常工作:

<form method="post" action="/indi id="indiform" enctype="multipart/form-data">
        <input type="file" name="myFile" id="myIndifile"/>
        <input type="submit" id="indisubmitbutton" value="Submit" name="upload" class="btn btn-primary" id = "uploadFile"/>   
</form>
Run Code Online (Sandbox Code Playgroud)

现在我想提交post来自 jQuery 的请求并将响应处理data为:

var file = $("#myIndifile")[0].files[0];
$.ajax({
    type: 'post',
    url: '/indi',
    async: false,
    data: JSON.stringify({ myFile:file }),
    contentType: "application/json",
    success: …
Run Code Online (Sandbox Code Playgroud)

javascript jquery form-data ajaxform node.js

5
推荐指数
1
解决办法
2296
查看次数

golang google oauth2 - 无法获取用户信息(库:https://github.com/golang/oauth2)

我使用以下库为google oauth2 https://github.com/golang/oauth2

我正在使用示例中给出的代码(网址:http://play.golang.org/p/qXyuaVEhyS,https://godoc.org/golang.org/x/oauth2/google)

我能够获得auth代码和令牌,但无法获取获取用户信息的get请求

MyCode:

conf := &oauth2.Config{
        ClientID:     "my client id",
        ClientSecret: "secred id",
        RedirectURL:  "http://localhost:3000/googlelogin",
        Scopes: []string{
            "https://www.googleapis.com/auth/userinfo.profile",
        },
        Endpoint: google.Endpoint,
    }

m.Get("/googleloginrequest", func(r render.Render, request *http.Request) {

    url := conf.AuthCodeURL("state")
    fmt.Printf("Visit the URL for the auth dialog: %v", url)

    r.Redirect(url)

})

m.Get("/googlelogin", func(r render.Render, request *http.Request) {

        authcode := request.FormValue("code")

        tok, err := conf.Exchange(oauth2.NoContext, authcode)
        if err != nil {
            log.Fatal(err)
        }

        client := conf.Client(oauth2.NoContext, tok)

        resp, err :=client.Get("https://www.googleapis.com/userinfo/v2/me")

        r.JSON(200, …
Run Code Online (Sandbox Code Playgroud)

oauth go google-oauth martini

1
推荐指数
1
解决办法
2834
查看次数