Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Regular Contributor
Posts: 56
Registered: ‎09-14-2011
My Device: 9000
My Carrier: b.tech

Upload Image to server

Hi

 

can any body tell me how to upload image to server any get or post method in blackberry 

 

 

 

Thanks

regards

naveen

Highlighted
Developer
Posts: 228
Registered: ‎10-01-2011
My Device: Passport

Re: Upload Image to server

You need to provide more details on what you are trying to do, it depends on what the server support.  If you are just looking for a basic idea on how to do a get / post you can do it like this:

 

protected HttpConnection conn = null;

protected String url = "http://www.mydummypostsite.com";

 

try {
      conn = (HttpConnection) Connector.open(url);
      conn.setRequestMethod(HttpConnection.POST);  <--- POST or GET
      conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=" + charset);
      OutputStream os = conn.openOutputStream();
      os.write(request.toString().getBytes());
      os.flush();
      InputStream is = conn.openInputStream();
      data = net.rim.device.api.io.IOUtilities.streamToBytes(is);
      is.close();
      s = new String(data);
   } catch (IOException e) {
   } catch (Exception e){
   }finally {
       if (conn != null) {
          try {
             conn.close();
          } catch (final IOException e2) {
    }
  }
}

 

If you want to send an image file then you will need to MIME encode it first I expect but it depends on the site. Also ensure you execute any of the conneciton code in a separate thread not he main thread or you applicaiton may hang.

 

----------------------------------------------------------------------------------

Press LIKE if I helped you