delaying dataHandler of file upload, is it possible?

88 views
Skip to first unread message

Paulo Lopes

unread,
Jun 18, 2013, 2:59:15 PM6/18/13
to ve...@googlegroups.com
I am facing a problem trying to handle file uploads. It could be that i am doing it wrong.

I have a request and i set 3 callbacks:

* uploadHandler
  - here i just keep a reference to all HttpServerFileUpload
* dataHandler
  - here is just keep track of the upload size. i accumulate the buffer size and if it is bigger than e predefined size i abort the request
endHandler
  - here i notify my app to continue

So after the endHandler is called I was setting the handlers on HttpServerFileUpload
* dataHandler
* endHandler

The problem is that when i set the handlers on
HttpServerFileUpload they never get called

So I tried to set them directly inside the uploadHandler and in this case it works.

Now i would like to *delay* to set the
HttpServerFileUpload handlers later since i might want to do some processing in between setting the original uploadHandler and the fileuploadHandlers is it possible?

I looked into the code and there is a pause and resume method on the
HttpServerFileUpload, however it pauses the whole request and does not work in my case.

I was thinking if there is such as thing that could hold the data in some buffer until the data/end handlers are set on the
HttpServerFileUpload.

Tim Fox

unread,
Jun 18, 2013, 3:18:18 PM6/18/13
to ve...@googlegroups.com
I don't follow. Maybe a concrete example will help?

Finn Bock

unread,
Jun 18, 2013, 4:06:48 PM6/18/13
to ve...@googlegroups.com
[Paulo Lopes]:
I am facing a problem trying to handle file uploads. It could be that i am doing it wrong.

I have a request and i set 3 callbacks:

* uploadHandler
  - here i just keep a reference to all HttpServerFileUpload
* dataHandler
  - here is just keep track of the upload size. i accumulate the buffer size and if it is bigger than e predefined size i abort the request
endHandler
  - here i notify my app to continue

So after the endHandler is called I was setting the handlers on HttpServerFileUpload
* dataHandler
* endHandler

The problem is that when i set the handlers on
HttpServerFileUpload they never get called

So I tried to set them directly inside the uploadHandler and in this case it works.

Now i would like to *delay* to set the
HttpServerFileUpload handlers later since i might want to do some processing in between setting the original uploadHandler and the fileuploadHandlers is it possible?

I can't see how that should be possible without having to store the file data somewhere (memory or an upload folder) and then when endHandler is called use the uploaded files.

I looked into the code and there is a pause and resume method on the HttpServerFileUpload, however it pauses the whole request and does not work in my case.
 
I don't think it can work any other way. The HttpServerFileUpload is part of the request and the only way to pause a file upload is to pause the whole request.

I was thinking if there is such as thing that could hold the data in some buffer until the data/end handlers are set on the HttpServerFileUpload.

Such a thing sound like a file on the filesystem :-) Thats what connect does f.ex. http://www.senchalabs.org/connect/multipart.html

regards,
Finn
Reply all
Reply to author
Forward
0 new messages