简体   繁体   中英

spring file upload, java heap size error

I have some strange error during file upload.
File size is ~300mb..
When i try to upload it, i catch "out of memory error: java heap space". I tried to increase heap size up to 3gb, but it's still not enough.
Configuration is:
Spring java config, spring jdbctemplate, mysql.
When i try to upload same file using other project (spring xml config, upload with executefunction, oracle), it takes 900mb from heap and uploads successfully.
Any ideas what is going on or any hints on how to find the problem?

  @RequestMapping(value = {"/add_file"}, method = {RequestMethod.POST}/*,
        params = {"file","path","parent_id"}*/)
public String addFile(
        @RequestParam("file") MultipartFile file,
        @RequestParam("parent_id") int parent_id,
        @RequestParam("path") String path,
        @RequestParam("id") int id
) {
    try {
        if (id == -1) fileDAO.addFile(file.getOriginalFilename(), file.getBytes(), parent_id);
        else fileDAO.updateFile(id, file.getBytes());
    } catch (IOException e) {
        e.printStackTrace();
    }
    return "redirect:" + path;
}
/* dao function */
        @Override
    public void addFile(String name, byte[] blob, int folder_id) {
        if (folder_id == 0) {
            jdbcTemplate.update("insert into file(name, content) VALUES(?,?)",
                    new Object[]{name, new SqlLobValue(blob)},
                    new int[]{Types.VARCHAR, Types.BLOB});
        } 
}

update : commented addFile content. Now it takes ~500mb for the whole process (for uploading file into controller, i suppose)

update2: Changed db to oracle - it works. So the problem is in mysql properties..?

使用MultipartFile.getInputStream()和MultipartFile.getSize()以及匹配的SqlLobValue构造函数。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM