1

How to handle big (large) file upload?

asked 2013-10-07 04:50:49 +0800

FrankyDude gravatar image FrankyDude
11 2

updated 2013-10-07 16:45:17 +0800

Hi all,

I was wondering what would be the solution for handling big file upload (let's say 50mb, but it could also be a couple gigabytes...)?

I am running Grails 2.0.x with ZKUI 0.5.4 (ZK 6.x) if my memory serves. I am using MVVM all over the place, and we are already able to manage file upload and file download, but since default file upload solution put the byte array representation of files being transferred into memory, server will eventually crash an out of memory exception if file is just too large.

1- What I am looking for is a solution for MVVM that, for uploads, uses the file's byte stream to saves the the file content directly on disk (through the use of a customizable - in size - buffer). This way, no matter how big the file is, there would never be an out-of-memory issue since we are not reading the 'whole' file into memory, just a piece of it for each read cycle (the buffer size).

2- (optional, but a very nice to have for end users uploading large files) How would you plug a progress bar to this solution while uploading?

Thank you for any help, Frank

delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2013-10-25 09:30:20 +0800

cor3000 gravatar image cor3000
4158 1 7
ZK Team

updated 2013-10-25 09:42:10 +0800

Hi Frank,

I just double-checked with a very simple example (using ZK 6.5.4) and ZK does exactly what you describe out of the box.

my streaming-upload.zul:

<zk>
    <div apply="org.zkoss.bind.BindComposer" 
            viewModel="@id('vm') @init('zk.forum.upload.StreamingUploadViewModel')" >
        <button id="upload" label="upload" upload="true"
            onUpload="@command('upload', media=event.media)" />
    </div>
</zk>

my View Model

package zk.forum.upload;

import org.zkoss.bind.annotation.BindingParam;
import org.zkoss.bind.annotation.Command;
import org.zkoss.util.media.Media;

public class StreamingUploadViewModel {
    @Command("upload") 
    public void onUpload(@BindingParam("media") Media media) {
        System.out.println(media.getStreamData());
    }
}

When you drag a large file over the button, it will start the upload, showing a progress bar giving you the chance to cancel the upload. Observing the memory, I could not notice any significant increase. And in the command handler method in the end you'll see that the stream is actually a FileInputStream. It is pointing to a temporary file in your user's temp folder.

If the behaviour is not the same in your case, please give me details about which exact ZK version you are using or an example to reproduce the memory increase leading to the exception.

Regards,

Robert

link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
2 followers

RSS

Stats

Asked: 2013-10-07 04:50:49 +0800

Seen: 50 times

Last updated: Oct 25 '13

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More