users@grizzly.java.net

Re: Grizzly fileupload

From: gagansnt <gagansnt_at_gmail.com>
Date: Tue, 15 Mar 2011 12:18:09 -0700 (PDT)

Thanks for the reply Alexey.

Not sure how to respond to your answer on grizzly mailing list. Because when
I try replying on the grizzly forum it says "You are not allowed to do that
(send lists)" So I am reply here only.

Your sample code may work for text or doc files but it won't work for binary
files. We may need NIOInputStream in that case. I was stuck in a problem
where I have to parse POST fileupload request. If I use NIOReader then
binary files got corrupted because of Char enconding problem and if I use
NIOInputStream then I had no way of getting the POST request boundary,
content-length info and know from which position actual file contents start.
Also there is no readLine function available in NIOReader or NIOInputStream
classes. I am putting all this just to help developers of the API to know.

What I did is...
1. I used Grizzly's NIOInputStream,
2. read initial chunk in a byte buffer,
3. Converted that buffer to a String
4. Split that String based on new line character and stored in a String
array
5. Read the first 4 files and parsed them further to extract relevant info,
stored boundary info separately so that I could know where file ends.
6. Sum the length of first 4 lines then added 4 in it to make for new line
character that I used to split the lines
7. Then Substring the original string from (length of first 4 lines+4,
String length)
8. Converted String to bytes again.
9. Read next chunks do the same and look for the boundary in them
10. When I got the boundary, I removed it from the contents and closed the
output file buffer and saved it.

One very important thing while doing byte to String and String to byte
conversion pls make sure you use Char encoding ISO8859_1 for example
String data = new String(buf,0,len,"ISO8859_1");
And data.getBytes("ISO8859_1")

Not sure how far I can go in it because my application is now very specific
and work on POST file uploads. I may be doing something wrong please let me
know if thr is any other easier and more elegant way.
 
A readline function would be handy if you people can add it.


oleksiys wrote:
>
> Hi Gagan,
>
> I just realized that you might use the Nabble mailing list and didn't get
> response notification [1].
> Until we're working on fixing this, you can check for the response on the
> java.net Grizzly mailing list directly [2].
>
> WBR,
> Alexey.
>
> [1]
> http://old.nabble.com/Grizzly-Nabble-mailing-list-is-temporary-unavailable-tt31152872.html
> [2] http://java.net/projects/grizzly/lists/users/archive/2011-03/message/8
>
>
>
> gagansnt wrote:
>>
>> I am working on a server application using Grizzly which can handle
>> uploading of very large files. I am looking for a sample example which
>> shows how to parse a POST request and save file on server side.
>>
>> If anybody had written such example then I would appreciate if you could
>> share it.
>>
>> Thanks in advance.
>> Gagan
>>
>
>

-- 
View this message in context: http://old.nabble.com/Grizzly-fileupload-tp31141535p31157072.html
Sent from the Grizzly - Users mailing list archive at Nabble.com.