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: 97
Registered: ‎09-21-2010
My Device: 8900
My Carrier: developer

sending of the image to the server

hi 

 

i am sending the image to the server ,but cant able to uplaod it ,

  HttpConnection conn = (HttpConnection) Connector.open("http://74.54.137.138:3017/Service.asmx/Upload", Connector.READ_WRITE, true);
                conn.setRequestMethod(HttpConnection.POST); 
//                conn.setRequestMethod(HttpProtocolConstants.HTTP_METHOD_POST);
                
                conn.setRequestProperty(HttpProtocolConstants.HEADER_CONTENT_TYPE, HttpProtocolConstants.CONTENT_TYPE_IMAGE_JPEG +";boundary="+boundary);
                conn.setRequestProperty(HttpProtocolConstants.HEADER_CONTENT_LENGTH, String.valueOf(_raw.length));
                conn.setRequestProperty( "x-rim-transcode-content", "none" );
                ByteArrayOutputStream out1 = new ByteArrayOutputStream();
                OutputStream finalOut = conn.openOutputStream();
                System.out.println("Boundary  ::::: 1");
                String newLine = "\r\n";
                out1.write(newLine.getBytes());
                out1.write("--".getBytes());
                out1.write(boundary.getBytes());
                out1.write(newLine.getBytes());
                System.out.println("Boundary  ::::: 2");
                String contDisp="Content-Disposition:form-data; name=\"Image.jpg\";filename=\"Image.jpg\"";
                String contEnc = "Content-Transfer-Encoding: binary";
                String type="Content-Type:image/jpeg";
                System.out.println("Boundary  ::::: 3");
                out1.write(contDisp.getBytes());
                out1.write(newLine.getBytes());
                out1.write(type.getBytes());
                out1.write(newLine.getBytes());
                out1.write(contEnc.getBytes());
                out1.write(newLine.getBytes());
                out1.write(newLine.getBytes());
                out1.write(_raw);
                out1.write(newLine.getBytes());
                out1.write("--".getBytes());
                out1.write(boundary.getBytes());
                out1.write("--".getBytes());
                out1.write(newLine.getBytes());
                finalOut.write(out1.toByteArray());
                System.out.println("hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh");
                StringBuffer sb = new StringBuffer();
    			InputStream is = conn.openDataInputStream();
    			int chr;
    			while ((chr = is.read()) != -1)
    			sb.append((char) chr);
    			System.out.println("Error message   :  "+sb.toString());
    			Dialog.alert(sb.toString());
    			out1.flush();
                out1.close();
                 
                finalOut.flush();
                finalOut.close();
                
//                Hashtable params = new Hashtable();
//                params.put("contents", _raw);
//                params.put("FileName", "image.jpeg");
//                 
//                HttpMultipartRequest req = new HttpMultipartRequest(
//                	"http://74.54.137.138:3017/Service.asmx",
//                	params,
//                	"Upload", "image.jpeg", "image/jpeg", _raw
//                );
//                 
//                byte[] response = req.send();
//               int hi = response.length;
//               System.out.println("hiiiiiiiiiiiiiiiiiiiii"+hi);
               
                

                // Close the connections
                out.close();
                file.close();
            }
            catch(Exception e)
            {
            	WelcomeScreen.errorDialog("ERROR " + e.getClass() + ":  " + e.getMessage());
            	System.out.println(e.getMessage());
            }

 i am using above code but cant able to send the image to the server .

 

Please provide me the solution or code for uploading the image to the server.

 

i am getting the request format error .

 

Please help 

 

Regards

Amrinder SIngh

Regular Contributor
Posts: 97
Registered: ‎09-21-2010
My Device: 8900
My Carrier: developer

Re: sending of the image to the server

Hi 

 

 

Please Help ,Please Please Smiley Sad

Smiley Sad

 

Regards

Amrinder Singh