ZK - Open Source Ajax Java FrameworkZK - Open Source Ajax Java Framework

Upload file with size less than 17 KB not working

alexandrecoelho
3 Feb 2012 17:42:01 GMT
3 Feb 2012 17:42:01 GMT

Hi,

I have tried to upload files with size less than 17 KB, but it is not working. Could you know inform me if exists any configuration to be done to upload files with size less than 17kb?

Thanks!!!!!!!

matthewgo
4 Feb 2012 03:45:25 GMT
4 Feb 2012 03:45:25 GMT

Hi alexandrecoelho,
Here is a demo without any other configuration: http://www.zkoss.org/zkdemo/file_handling/file_upload
Can you show us your code and configuration?

alexandrecoelho
6 Feb 2012 19:49:24 GMT
6 Feb 2012 19:49:24 GMT

Hi, thanks!!

The upload it´s working, but when i create a file with the uploaded media, the size of file is 0KB. That just happened with files less than 17KB.

The part of code is:

		Media media = ((UploadEvent)event).getMedia();

		String path = Executions.getCurrent().getDesktop().getWebApp().getRealPath("/arquivos") + "\\"; 

		try {
		
	          if (media.isBinary()) {
				File dest = new File(path + media.getName());
				Files.copy(dest, media.getStreamData());
			}
			else {
				BufferedWriter writer = new BufferedWriter(new FileWriter(path + media.getName()));
				Files.copy(writer, media.getReaderData());
			}

		} catch (IOException e) {
			e.printStackTrace();
		}

mjablonskiTop Contributor
9 Feb 2012 09:18:59 GMT
9 Feb 2012 09:18:59 GMT

Hi,

you have to check if the media is present in memory when creating the appropriate input stream / reader. Here's an example:

InputStream stream = new BufferedInputStream(media.inMemory() ? new ByteArrayInputStream(media.getByteData()) : media.getStreamData());
...
Reader reader = new BufferedReader(media.inMemory() ? new StringReader(media.getStringData()) : media.getReaderData());


Cheers, Maik