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

DC 6-12V 6Bit LED Digital Clock Red Light Common Anode With Memory Function
$6.52
DC 6-12V 6Bit LED Digital Clock Red Light Common Anode With Memory Function pictureKronos 480F Time Clock w/Ethernet Card w/512k Memory / KOS-3D & Power Supply
$99.0
Kronos 480F Time Clock w/Ethernet Card w/512k Memory / KOS-3D & Power Supply pictureGE FANUC IC693CPU351-HT CPU MODULE 240K USER MEMORY IC693CPU351HT
$703.26
GE FANUC IC693CPU351-HT CPU MODULE 240K USER MEMORY IC693CPU351HT pictureNEC DS2000 Expansion Memory CPU Card WITH 4 Hour IntraMail
$100.0
NEC DS2000 Expansion Memory CPU Card WITH 4 Hour IntraMail pictureAllen Bradley 1747-M11 Ser B SLC 500 Memory Module EPROM NEW
$35.15
Allen Bradley 1747-M11 Ser B SLC 500 Memory Module EPROM  NEW picture






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