File Upload with rpc call

1,038 views
Skip to first unread message

loudo

unread,
Apr 14, 2009, 5:18:13 AM4/14/09
to Google Web Toolkit
Hello

Can i make a file upload with a rpc call ?
I want to upload a file with the rpc call but i have not found
example.
I have only found example with submit form.

Thanks a lot for your response.

Vitali Lovich

unread,
Apr 14, 2009, 5:45:23 AM4/14/09
to Google-We...@googlegroups.com
No, obviously not as that would imply reading the file which violates the whole sandboxing browsers take with respect to javascript.

The only thing you can do is submit the file (whereby the browser is responsible for actually reading & transmitting the file) & then use RPC to manipulate the file that is on the server.

Prashant Gupta

unread,
Apr 14, 2009, 5:58:40 AM4/14/09
to Google-We...@googlegroups.com
by this method, if file size is large, it may take very long time or even fail if network is slow. can't we break file into smaller parts before sending and send one-by-one and then rejoin it at server?

Vitali Lovich

unread,
Apr 14, 2009, 6:18:33 AM4/14/09
to Google-We...@googlegroups.com
No, not with native Javascript.  You have to have the user do it manually & upload the parts - the rejoining can be done automatically on the server.  One way would be through the use of multi-part archives.

Or use the flash-based approaches that seem to be popular.  http://mike.kruckenberg.com/archives/2008/02/inline-web-browser-file-upload.html, although even they may not give you what you want.  Web browsers were never really meant for uploading large amounts of data to servers but instead to go the other way.

Rakesh

unread,
Apr 14, 2009, 5:40:40 PM4/14/09
to Google Web Toolkit
Look into google gears. You can upload a file of up to 1 GB in youtube
with google gears installed.
Look for:
Blob slice(offset, length)
and
HttpRequest API

Vitali Lovich

unread,
Apr 14, 2009, 5:51:22 PM4/14/09
to Google-We...@googlegroups.com
That would of course necessitate your users installing gears (penetration of which is limited at best I think).

wenxing zheng

unread,
Apr 14, 2009, 9:30:22 PM4/14/09
to Google-We...@googlegroups.com
BTW, is there a solution to transfer a large file exceeding more than 1G bytes between two hosts on the net?
The transfer speed won't make the end user lose their patience.


Best regards,

Vitali Lovich

unread,
Apr 15, 2009, 12:21:21 AM4/15/09
to Google-We...@googlegroups.com
Between two servers yes (just use any regular file-transfer mechanism such as ftp, webdav, sshfs, etc).  Between two clients obviously not as that defeats all sorts of browser security.  You can't even do that with flash I believe.

Maybe in the future there might be some kind of mechanism to establish a connection between browsers directly, but you've got to remember that HTML was created as a client/server architecture & all features pretty much assume this behaviour.

If you want to transfer files directly between users, then webapps are the wrong tool.  Especially with big apps, use something like Bittorrent instead.

evgeniy

unread,
Apr 15, 2009, 7:12:04 AM4/15/09
to Google Web Toolkit
Yes, you can do it only in FireFox 3, as far as I know.
If you have FileUpload element then you can acces to file's data from
native JavaScript.
For example you have FileUpload and set its ID to "file" then
following method returns binary data contained in file:
private native String getFileBinary() /*-{
return $doc.getElementById("file").files[0].getAsBinary();
}-*/;
Then you are free to use returned data in RPC call or whatever you
want.

You can read more here: https://developer.mozilla.org/En/NsIDOMFile

Vitali Lovich

unread,
Apr 15, 2009, 12:39:39 PM4/15/09
to Google-We...@googlegroups.com
http://igstan.blogspot.com/2009/01/pure-javascript-file-upload.html

From the comments you cannot read more than 100MB (although I doubt this is an actual restriction) & you have to read the whole file (meaning large files will pause your program for quite a while).

More importantly, this is FF3 only, which leaves out users of any other browser which is even worse than the flash option.

Vitali Lovich

unread,
Apr 15, 2009, 12:43:01 PM4/15/09
to Google-We...@googlegroups.com
On Wed, Apr 15, 2009 at 12:39 PM, Vitali Lovich <vlo...@gmail.com> wrote:
http://igstan.blogspot.com/2009/01/pure-javascript-file-upload.html

From the comments you cannot read more than 100MB (although I doubt this is an actual restriction) & you have to read the whole file (meaning large files will pause your program for quite a while).
Sorry - meant to make it clear, particularly since this is FF specific (if Chrome had this API, it would only apply to the tab), this will hang your browser until the entire file is read into memory.  Only background threads would solve this issue, but that would further lower your user base to FF 3.5 & Google Gears users (assuming you created an API wrapper that supported both).
Reply all
Reply to author
Forward
0 new messages