Http upload with codename one

866 views
Skip to first unread message

chibexme

unread,
Mar 17, 2012, 4:01:57 PM3/17/12
to codenameone...@googlegroups.com
I want to browse folders/files on the phone, pick a file (eg txt file) and upload that file to remote web server. Please how can i do that with CodenameOne?

thank you.

Shai Almog

unread,
Mar 18, 2012, 12:33:02 AM3/18/12
to codenameone...@googlegroups.com
You can list the File's with the FileSystemStorage API, the FileTree has an example but its pretty buggy at the moment http://code.google.com/p/codenameone/issues/detail?id=97

To upload a small file you can just add its content as an argument to a post request, just create a ConnectionRequest set the URL and addArgument with the file content.
For larger files you will have to create a multipart-mime upload client/server implementation. You can just derive the ConnectionRequest and implement the logic by overriding the appropriate methods. Since I didn't do this in Codename One I don't have specific pointers I can give you there, we probably should offer something like this builtin in the future (as we should offer many other things too).

Akintayo Olusegun

unread,
Apr 19, 2012, 10:49:43 AM4/19/12
to codenameone...@googlegroups.com
Has anyone been able to successfully do a file upload with codename1?

Thanks

Shai Almog

unread,
Apr 19, 2012, 1:49:10 PM4/19/12
to codenameone...@googlegroups.com
To upload files over HTTP (unrelated to codename one) you will need multipart support and a server that can accept these requests. I implemented a multipart connection request in the current version of Codename One but never tested it. You can look at the code to see how its supposed to work in theory.

Shai Almog

unread,
Apr 20, 2012, 12:44:47 PM4/20/12
to codenameone...@googlegroups.com
No, it won't.

austi...@gmail.com

unread,
Apr 20, 2012, 2:10:21 PM4/20/12
to codenameone...@googlegroups.com
Hmm...ok then, i'm trying a workaround. When it works i shall let the community know.

On Friday, April 20, 2012 5:44:47 PM UTC+1, Shai Almog wrote:
No, it won't.

austi...@gmail.com

unread,
Apr 20, 2012, 10:42:00 AM4/20/12
to codenameone...@googlegroups.com
Would FTP work in CN1? That might help.
Reply all
Reply to author
Forward
0 new messages