spring boot上传zip文件很慢

时间:2018-04-28 11:10:29

标签: spring performance spring-boot upload zipfile

我正在使用Spring启动上传文件到服务器。我发现了一些奇怪的东西。当我上传一个4.88MB的Jpg文件时,它需要8.47s,但是一个3.16M的zip文件,需要大约1.3分钟。考虑到这个压缩文件包含900多个小文件。我更改了另一个包含10个小文件的zip文件。现在传输数据需要33.96秒,即使这个新的zip文件是6.52M,比旧文件还要大。

zip文件中的文件数量是否会影响上传速度?如果是这样,为什么?

application.yml:

spring:
  http:
    multipart:
      enabled: true
      max-file-size: 20MB

java:

@RequestMapping("/changeMainAttachment")
@ResponseBody
public Object addChangeMainAttachment(@RequestParam("changeMainAttachment[]") MultipartFile[] files){
    String fileSavePath = gunsProperties.getFileUploadPath();
    for (MultipartFile multipartFile : files) {
        String fileName = UUID.randomUUID() + "#_#_#" + multipartFile.getOriginalFilename();
        try {

            logger.info("file uploaded to: " + fileSavePath + fileName);
            multipartFile.transferTo(new File(fileSavePath + fileName));
        } catch (Exception e) {
            throw new BussinessException(BizExceptionEnum.UPLOAD_ERROR);
        }

    }
    return new Msg();   

}

在正面,我使用Bootstrap File-input

JS:

initFileInput: function(select,_url,_showZone,_async,befordUpload,afterUploaded){
        var i = $(select).fileinput({
            theme: "gly",
            uploadUrl: _url,
            dropZoneEnabled: _showZone,
            uploadAsync: _async,
            showUpload: true,
            showUploadedThumbs: true,
            maxFileSize: 20*1024,
            maxFileCount: 5, 
            msgFilesTooMany: "选择上传的文件数量({n}) 超过允许的最大数值{m}!",
            hideThumbnailContent: true // hide image, pdf, text or other content in the thumbnail preview
        });
        if(befordUpload && typeof befordUpload == 'function'){
            i.on('filebatchpreupload',befordUpload);
        }
        if(afterUploaded && typeof afterUploaded == 'function'){
            i.on('filebatchuploadcomplete',afterUploaded);
        }


    }

我通过以下方式调用此方法

ChangeAdd.initFileInput("#changeMainAttachment", /change/changeMainAttachment", true, true, ChangeAdd.fileBeforeUpload, ChangeAdd.fileAfterUploaded);

0 个答案:

没有答案