上周遇到这样一个问题,客户上传高清视频(1G以上)的时候上传失败。
一开始以为是session过期或者文件大小受系统限制,导致的错误。
查看了系统的配置文件没有看到文件大小限制,
web.xml中seesiontimeout是30,我把它改成了120。
但还是不行,有时候10分钟就崩了。
同事说,可能是客户这里服务器网络波动导致网络连接断开,我觉得有点道理。
但是我在本地测试的时候发觉上传也失败,网络原因排除。
看了日志,错误为:
java.lang.OutOfMemoryError Java heap space
上传文件代码如下:
public static String uploadSingleFile(String path,MultipartFile file) {
if (!file.isEmpty()) {
byte[] bytes;
try {
bytes = file.getBytes();
// Create the file on server
File serverFile = createServerFile(path,file.getOriginalFilename());
BufferedOutputStream stream = new BufferedOutputStream(
new FileOutputStream(serverFile));
stream.write(bytes);
stream.flush();
stream.close();
l