Zuul上傳文件


對於1M以內的文件上傳,無需任何處理,大文件10M以上需要為上傳路徑添加/zuul前綴,也可使用zuul.servlet-path自定義前綴
如果Zuul使用了Ribbon做負載均衡,那么對於超大的文件,需要提升超時設置:hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds:60000
ribbon:
    ConnectTimeout: 3000
    ReadTimeout: 60000
 
將服務注冊到Eureka Server上,並配置文件上傳大小的限制,配置文件添加以下內容:
    server:
        port: 8050
    eureka:
        client:
            serviceUrl:
                defaultZone: http://localhost:8761/erueka/
            instance:
                prefer-ip-address: true
    spring:
        application:
            name: microservice-file-upload
        http:
            multipart:
                max-file-size: 2000Mb    (默認1M)
                max-request-size: 2500Mb (默認10M)
 
@ReponseBody
@Controller
public class FileUploadController{
    @RequestMapping(value = "/upload", method = RequestMethod.POST)
    public String handleFileUpload(@RequestParam(value = "file", required = true) MultipartFile file) throws IOException{
        byte[] bytes = file.getBytes();
        File fileToSave = new File(file.getOriginalFilename());
        FileCopyUtils.copy(bytes fileToSave);
        return fileToSave.getAbsolutePath();
    }
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM