BlackBerry Forums Support Community               

View Poll Results: Can't able to upload image from BB Device while uploading from Simulator
Option1 0 0%
Option2 0 0%
Voters: 0. You may not vote on this poll

Closed Thread
 
LinkBack Thread Tools
Old 11-18-2009, 06:33 AM   #1 (permalink)
New Member
 
Join Date: Jun 2009
Model: 8300
PIN: N/A
Carrier: sdf
Posts: 1
Post Thanks: 0
Thanked 0 Times in 0 Posts
Smile Can't able to upload image from BB Device while uploading from Simulator

Please Login to Remove!

Hi All,
I can able to upload image from below given code from my blackberry simulator. But this same code can't work on the real device (BB 7310). I have used the php script at server side (xaamp server). Please give me any solution or prepared modified code with correction in my code. My code is given below for BB.

public synchronized boolean uploadImage(){
boolean isCompleted=true;
HttpConnection conn;
try{
String boundary = "Some_Unique_Text_Also_Alphanumeric";
logMessage = "11>>";
EventLogger.logEvent(GUID,logMessage.getBytes());
byte[] Bytes_Of_Image_To_Be_Uploaded = IOUtilities.streamToBytes(this.getClass().getResou rceAsStream("Lady.jpg"));
logMessage = "22>>";
EventLogger.logEvent(GUID,logMessage.getBytes());
conn = (HttpConnection) Connector.open(myurl,Connector.READ_WRITE);
logMessage = "33>>";
EventLogger.logEvent(GUID,logMessage.getBytes());
conn.setRequestMethod(HttpConnection.POST);
logMessage = "44>>";
EventLogger.logEvent(GUID,logMessage.getBytes());
conn.setRequestProperty(HttpProtocolConstants.HEAD ER_CONTENT_TYPE, HttpProtocolConstants.CONTENT_TYPE_MULTIPART_FORM_ DATA+";boundary="+boundary);
logMessage = "55>>";
EventLogger.logEvent(GUID,logMessage.getBytes());
conn.setRequestProperty(HttpProtocolConstants.HEAD ER_CONTENT_LENGTH, String.valueOf(Bytes_Of_Image_To_Be_Uploaded.lengt h));
logMessage = "66>>";
EventLogger.logEvent(GUID,logMessage.getBytes());

conn.setRequestProperty( "x-rim-transcode-content", "none" );
logMessage = "77>>";
EventLogger.logEvent(GUID,logMessage.getBytes());
ByteArrayOutputStream out = new ByteArrayOutputStream();
logMessage = "88>>";
EventLogger.logEvent(GUID,logMessage.getBytes());
OutputStream finalOut = conn.openOutputStream();
logMessage = "99>>";
EventLogger.logEvent(GUID,logMessage.getBytes());
String newLine = "\r\n";
out.write(newLine.getBytes());
logMessage = "10 10>>";
EventLogger.logEvent(GUID,logMessage.getBytes());
out.write("--".getBytes());
logMessage = "11 11>>";
EventLogger.logEvent(GUID,logMessage.getBytes());
out.write(boundary.getBytes());
logMessage = "12 12>>";
EventLogger.logEvent(GUID,logMessage.getBytes());
out.write(newLine.getBytes());
logMessage = "13 13>>";
EventLogger.logEvent(GUID,logMessage.getBytes());
String contDisp="Content-Disposition:form-data; name=\"media\";filename=\"Lady.jpg\"";
String contEnc = "Content-Transfer-Encoding: binary";
String type="Content-Type:image/jpeg";

out.write(contDisp.getBytes());
logMessage = "14 14>>";
EventLogger.logEvent(GUID,logMessage.getBytes());
out.write(newLine.getBytes());
logMessage = "15 15>>";
EventLogger.logEvent(GUID,logMessage.getBytes());
out.write(type.getBytes());
logMessage = "16 16>>";
EventLogger.logEvent(GUID,logMessage.getBytes());

out.write(newLine.getBytes());
logMessage = "17 17>>";
EventLogger.logEvent(GUID,logMessage.getBytes());
out.write(contEnc.getBytes());
logMessage = "18 18>>";
EventLogger.logEvent(GUID,logMessage.getBytes());
out.write(newLine.getBytes());
logMessage = "19 19>>";
EventLogger.logEvent(GUID,logMessage.getBytes());
out.write(newLine.getBytes());
logMessage = "20 20>>";
EventLogger.logEvent(GUID,logMessage.getBytes());
out.write(Bytes_Of_Image_To_Be_Uploaded);
logMessage = "21 21>>";
EventLogger.logEvent(GUID,logMessage.getBytes());
out.write(newLine.getBytes());
logMessage = "22 22>>";
EventLogger.logEvent(GUID,logMessage.getBytes());
out.write("--".getBytes());
logMessage = "23 23>>";
EventLogger.logEvent(GUID,logMessage.getBytes());
out.write(boundary.getBytes());
logMessage = "24 24>>";
EventLogger.logEvent(GUID,logMessage.getBytes());
out.write("--".getBytes());
logMessage = "25 25>>";
EventLogger.logEvent(GUID,logMessage.getBytes());
out.write(newLine.getBytes());
logMessage = "26 26>>";
EventLogger.logEvent(GUID,logMessage.getBytes());
finalOut.write(out.toByteArray());
logMessage = "27 27>>";
EventLogger.logEvent(GUID,logMessage.getBytes());
//InputStream in = conn.openInputStream();


out.flush();
out.close();
finalOut.flush();
finalOut.close();

logMessage = "28 28>>";
EventLogger.logEvent(GUID,logMessage.getBytes());

}catch(Exception e){
System.out.println("Exception in imageUpload1>>> :"+e.getMessage());
//Dialog.alert("Exception Caught in imageUpload1"+e.getMessage());
EventLogger.logEvent(GUID,e.getMessage().getBytes( ));
EventLogger.logEvent(GUID,String.valueOf(conn.getR esponseCode()).getBytes());
isCompleted=false;
}
return isCompleted;
}



Thanks In Advance.
Tej
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Dell Electronics PowerEdge 2950 Server (9424)
$49.95
Dell Electronics PowerEdge 2950 Server (9424) picturePortwell Single Board Computer B9300324AB18820820 S21 Dual Intel Xeon 2.8GHz SBC
$645.0
Portwell Single Board Computer B9300324AB18820820 S21 Dual Intel Xeon 2.8GHz SBC pictureNew HP Proliant DL380 Gen4/ML370 Server Intel Xeon Processor 311584-B21
$41.99
New HP Proliant DL380 Gen4/ML370 Server Intel Xeon Processor 311584-B21 pictureHp Proliant Microserver Gen8 Ultra Micro Tower Server - 1 X Intel Xeon E3-1220L
$830.49
Hp Proliant Microserver Gen8 Ultra Micro Tower Server - 1 X Intel Xeon E3-1220L pictureHp Proliant Microserver Gen8 Ultra Micro Tower Server - 1 X Intel Xeon E3-1220L
$707.85
Hp Proliant Microserver Gen8 Ultra Micro Tower Server - 1 X Intel Xeon E3-1220L picture






Copyright 2004-2016 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.