鍍金池/ 問答/Java  HTML/ ajax異步上傳文件,后臺(tái)springcloud,大文件異常

ajax異步上傳文件,后臺(tái)springcloud,大文件異常

1、### 問題描述
上傳大文件失?。y試1.3g),圖片可以上傳成功

clipboard.png

問題出現(xiàn)的環(huán)境背景及自己嘗試過哪些方法

官網(wǎng)上說的是大文件加/zuul表明是大文件,跳過網(wǎng)關(guān)代理

clipboard.png

相關(guān)代碼

// 請(qǐng)把代碼文本粘貼到下方(請(qǐng)勿用圖片代替代碼)
zuul網(wǎng)關(guān)配置

zuul:
  routes:
    service-video:
      path: /video/**
      sensitiveHeaders: 
      service-id: service-video
  sensitiveHeaders:
 上傳服務(wù)接口
    @RequestMapping(value = "/uploadFile", method = RequestMethod.POST)
    @HystrixCommand(fallbackMethod="uploadFallback")
    public String uploadFile(@RequestParam("uploadfile") MultipartFile uploadFile,HttpServletRequest request) throws IOException {
        JSONObject response = new JSONObject();
        
        String attachName = request.getParameter("attachName");
        String tag = request.getParameter("tag");//文件夾名
        String path = "img";
        
        InputStream stream = uploadFile.getInputStream();
        
        if(StringUtils.isNotEmpty(tag)) {
            path = tag;
        }
        
        attachName = "[" + CommonUtil.getDataFormat(new Date(), "yyyyMMddHHmmssSSS") + "]" + attachName;
        
        UploadFile ftp = new UploadFile();
        boolean flag = ftp.UploadFileToServer(stream,attachName, path);
        
        response.put("success", flag);
        response.put("uploadFileName", attachName);
        
        return response.toString();
    }

前端調(diào)用

    $.ajax({
                    url: server + "/zuul/video/uploadFile",
                    data: formFile,
                    type: "Post",
                    dataType: "json",
                    cache: false, //上傳文件無需緩存
                    processData: false, //用于對(duì)data參數(shù)進(jìn)行序列化處理 這里必須false
                    contentType: false, //必須
                    xhr: function () {
                        var myXhr = $.ajaxSettings.xhr();
                        if (myXhr.upload) {
                            myXhr.upload.addEventListener("progress", function (e) {
                                console.log("in Download progress");
                                if (e.lengthComputable) {
                                    var percentComplete = Math.round((e.loaded / e.total) * 100);
                                    console.log(percentComplete);
                                    $("#video-progress-width").css("width", percentComplete + '%');
                                } else {
                                    console.log("Length not computable.");
                                }
                            }, false);
                        }
                        return myXhr;
                    },
                    beforeSend: function () {
                        $("#video-progress").show();
                    },
                    complete: function () {
                        $("#video-progress").hide();
                    },
                    success: function (result) {
                        $("#chooceVideo").removeAttr("disabled");
                        $("#chooceVideo").val("選擇視頻");
                        if (result.success) {
                            that.uploadVideoFileshow = true;
                            $("#uploadVideoPath").val(result.uploadFileName);
                        } else {
                            layer.alert("上傳視頻失敗!");
                        }
                    },
                    error: function () {
                        $("#video-progress").hide();
                        $("#chooceVideo").removeAttr("disabled");
                        $("#chooceVideo").val("選擇視頻");
                        layer.alert("上傳視頻失敗!");
                    }
                })

你期待的結(jié)果是什么?實(shí)際看到的錯(cuò)誤信息又是什么?

文件上傳成功,小文件是可以上傳的

回答
編輯回答
夏木
切片后在上傳吧,這樣就能跳過限制,還能顯示進(jìn)度條
2018年7月21日 05:31
編輯回答
扯不斷

這搞不好是springboot的限制,有沒有配置max-file-size?

2018年5月8日 03:23