I need to upload a file through http or ftp to the website in blackberry jde.
A:
High level view: You open an OutputStream from an HttpConnection and write your data into that output stream. The main problem is going to be choosing which network connection to use (I recommend looking at this, unless you're on OS 5.0 which has a similar feature built in). As to uploading through FTP that will be somewhat more difficult as there is no support for FTP built into the BlackBerry API instead you'll have to look at using a SocketConnection and implementing part of FTP yourself.
Here's some code to get you started:
HttpConnection httpConn = (HttpConnection) Connector.open("<URL>");
FileConnection fileConn = (FileConnection) Connector.open("file:///<path>");
InputStream in = fileConn.openInputStream();
OutputStream out = httpConn.openOutputStream();
byte[] buffer = new byte[100];
int bytesRead = 0
while((in.read(buffer) = bytesRead) > 0)
{
out.write(buffer, 0, bytesRead);
}
Of course you'll need to deal with exceptions, close the streams, check that it was uploaded successfully, etc
Jonathan
2010-05-07 15:20:22