We use a the p:fileUpload widget form primefaces with an upload listener like this:

<p:fileUpload fileUploadListener="#{logic.uploadFile}
In the listener method we copy the file content to an byte array on a data class to store it later. The script looks like this:

byte[] content = IOUtils.toByteArray(in.fileUploadEvent.getFile().getInputstream());

But after uploading multiple files we get an OutOfMemoryError: Java heap space

asked 06.05.2015 at 09:27

SupportIvyTeam's gravatar image

SupportIvyTeam ♦♦
1.4k102118122
accept rate: 77%

edited 06.05.2015 at 09:54


If you store the whole content of a file into a byte array the whole content is held in the RAM. If the byte array is stored to the Dialog data the data is held until the dialog is closed with the Exit End or the session is destroyed. Normally the session gets only destroyed if the session timeout expires. So that means it is normally not a good idea to store file contents on byte arrays (in RAM). This will lead later or sooner to memory problems. You should store the file again as file on the server. As example:

FileUploadEvent fileUploadEvent = ... // get it from param
String fileName = fileUploadEvent.getFile().getFileName();
InputStream inputStream = fileUploadEvent.getFile().getInputstream();
// This creates a temporary session file which will be removed if the session terminates
File ivyfile = new ch.ivyteam.ivy.scripting.objects.File(fileName, true);
FileOutputStream fileOutputStream = new FileOutputStream(ivyfile.getJavaFile());
IOUtils.copy(inputStream, fileOutputStream);
    IOUtils.copy(inputStream, fileOutputStream);
link

answered 06.05.2015 at 09:54

Christian%20Strebel's gravatar image

Christian St... ♦
3.2k31338
accept rate: 88%

edited 06.05.2015 at 10:28

SupportIvyTeam's gravatar image

SupportIvyTeam ♦♦
1.4k102118122

The documentation of ch.ivyteam.ivy.scripting.objects.File says:

public File(String path, boolean temporary) throws IOException

temporary - if true then a temporary file will be created, otherwise a persistent file will be created

Question: When will the temporary file be deleted?

(06.05.2015 at 10:24) HaraldWeber HaraldWeber's gravatar image

The temporary file will be removed if the session terminates, normally if the session timeout expires. The session also is closed if the server or designer is closed.

(06.05.2015 at 10:33) Christian St... ♦ Christian%20Strebel's gravatar image

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×79
×5

Asked: 06.05.2015 at 09:27

Seen: 7,363 times

Last updated: 06.05.2015 at 10:33