찾다

 >  Q&A  >  본문

javascript - 七牛报错"error":"token not specified"

客户端<script type="text/javascript">

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

<code>function upLoad(uploadCallback) {

    $.ajax({

        type : 'POST',

        url : '${basePath}upload',

        success : function(dataStr, status) {

            uploadCallback(dataStr.token);

        },

        error : function(data, status, e) {

        }

 

    });

}

 

function uploadCallback(token) {

    $.ajaxFileUpload({

        url : 'http://up.qiniu.com/',

        secureuri : false,

        date : {

            'token' : token,

            'key':'test'

        },

        dataType : 'json',

        type : 'post',

        success : function(dataStr, status) {

        },

        error : function(data, status, e) {

 

        }

    });

}</code>

</script>
</head>
<body>

1

2

3

4

<code>    <input type="file" name="file" class="file-upload" id="upload"

        onchange="upLoad(

         uploadCallback

         );" /></code>

</body>
服务端
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

1

2

3

4

5

6

7

8

9

<code>    Gson gson = new Gson();

    Map<String, Object> r = new HashMap<String, Object>();

    String token=QiniuConfig.getUpToken();

    r.put("token", token);

    String data = gson.toJson(r);

    response.getWriter().write(data);

     

}

/**</code>

    • 生成Token

    • @return
      */

    1. static String getUpToken() {

      1

      2

      3

      4

      5

      6

      7

      8

      9

      <code>   return auth

                 .uploadToken(

                         QiniuConfig.bucket,

                         null,

                         3600,

                         new StringMap()

                                 .putNotEmpty(

                                         "returnBody",

                                         "{\"key\": $(key), \"hash\": $(etag), \"width\": $(imageInfo.width), \"height\": $(imageInfo.height)}"));</code>

      }

    自己做的demo为什么老是报错token not specified,请大神指导下

    PHP中文网PHP中文网2836일 전1933

    모든 응답(0)나는 대답할 것이다

    답장 없음
  • 취소회신하다