@@ -478,14 +478,15 @@ func (c *Server) Index(w http.ResponseWriter, r *http.Request) {
478478 <input type="text" id="code" name="code" value="" /></span>
479479 <span class="form-line">自定义认证(auth_token):
480480 <input type="text" id="auth_token" name="auth_token" value="" /></span>
481- <input type="submit" name ="submit" value="upload" / >
481+ <button type="button" id ="submit" value="upload" >上传</button >
482482 </form>
483483 </div>
484484 <div>断点续传(如果文件很大时可以考虑)</div>
485485 <div>
486486
487487 <div id="drag-drop-area"></div>
488488 <script src="https://transloadit.edgly.net/releases/uppy/v0.30.0/dist/uppy.min.js"></script>
489+ <script src="/%s/static/js/jquery.min.js"></script>
489490 <script>var uppy = Uppy.Core().use(Uppy.Dashboard, {
490491 inline: true,
491492 target: '#drag-drop-area'
@@ -499,6 +500,33 @@ func (c *Server) Index(w http.ResponseWriter, r *http.Request) {
499500 uppy.setMeta({ auth_token: '9ee60e59-cb0f-4578-aaba-29b9fc2919ca',callback_url:'http://127.0.0.1/callback'})//自定义参数与普通上传类似(虽然支持自定义,建议不要自定义,海量文件情况下,自定义很可能给自已给埋坑)
500501 </script>
501502 </div>
503+ <script>
504+ $(document).ready(function() {
505+ $("#submit").click(function(e) {
506+ e.preventDefault(); // 阻止表单默认提交
507+
508+ var formData = new FormData($("form").get(0));
509+ var authToken = $("#auth_token").val(); // 获取 auth_token 输入框的值
510+
511+ $.ajax({
512+ url: $("form").attr('action'),
513+ type: 'POST',
514+ data: formData,
515+ headers: {
516+ 'auth-token': authToken // 将 auth_token 放入请求头
517+ },
518+ processData: false,
519+ contentType: false,
520+ success: function(response) {
521+ alert("上传成功"+response);
522+ },
523+ error: function(xhr, status, error) {
524+ alert("上传失败: " + error);
525+ }
526+ });
527+ });
528+ });
529+ </script>
502530 </body>
503531 </html>`
504532 uppyFileName := STATIC_DIR + "/uppy.html"
@@ -512,7 +540,7 @@ func (c *Server) Index(w http.ResponseWriter, r *http.Request) {
512540 c .util .WriteFile (uppyFileName , uppy )
513541 }
514542 fmt .Fprintf (w ,
515- fmt .Sprintf (uppy , uploadUrl , Config ().DefaultScene , uploadBigUrl ))
543+ fmt .Sprintf (uppy , uploadUrl , Config ().DefaultScene , Config (). Group , uploadBigUrl ))
516544 } else {
517545 w .Write ([]byte ("web upload deny" ))
518546 }
0 commit comments