BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 02-15-2010, 10:34 AM   #1 (permalink)
New Member
 
Join Date: Feb 2010
Model: 8900
PIN: N/A
Carrier: Dialog
Posts: 6
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Second Upload Failing

Please Login to Remove!

We are developing an app to upload number of similar items in a batch.

The problem is the first item is getting uploaded perfectly but from the second item onwards it will fail (the upload size is different slightly).

If I use WiFi it works perfectly, this happens only when I use the carrier network. (Rogers, AT&T)

Can some one help me.

Arjuna.
TheArjuna.com, TheArjuna.net
Offline  
Old 02-15-2010, 10:43 AM   #2 (permalink)
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
Post Thanks: 0
Thanked 34 Times in 33 Posts
Default

How does it "fail"?
Offline  
Old 02-15-2010, 11:06 AM   #3 (permalink)
BlackBerry Extraordinaire
 
Join Date: Jan 2006
Model: LEZ10
OS: 10.0.10
Carrier: Rogers CA
Posts: 1,704
Post Thanks: 20
Thanked 77 Times in 68 Posts
Default

Are you using Direct TCP or BIS via Rogers? There is an upper limit on the size of an object downloaded via BIS. Can't remember exactly what it is, but it isn't very large.
__________________
My other Blackberry is a PlayBook.
Offline  
Old 02-16-2010, 02:35 AM   #4 (permalink)
New Member
 
Join Date: Feb 2010
Model: 8900
PIN: N/A
Carrier: Dialog
Posts: 6
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm just getting TCP received timeout error.

I use Direct TCP and also mainly im uploading items to a https server.
Offline  
Old 02-16-2010, 10:12 AM   #5 (permalink)
BlackBerry Extraordinaire
 
Join Date: Jan 2006
Model: LEZ10
OS: 10.0.10
Carrier: Rogers CA
Posts: 1,704
Post Thanks: 20
Thanked 77 Times in 68 Posts
Default

Didn't your profile carrier used to be Rogers? Who is Dialog?
__________________
My other Blackberry is a PlayBook.
Offline  
Old 02-17-2010, 12:53 AM   #6 (permalink)
New Member
 
Join Date: Feb 2010
Model: 8900
PIN: N/A
Carrier: Dialog
Posts: 6
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Actually the thing is I am in Sri Lanka. Dialog is the SL carrier. But my client is in Rogers network.

But in both places I get the issue.
Offline  
Old 02-17-2010, 07:38 AM   #7 (permalink)
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
Post Thanks: 0
Thanked 34 Times in 33 Posts
Default

If you get the problem in both networks, then the issue is in your code.

Are you trying to reuse a stream, or a connection? Maybe you should post some code.
Offline  
Old 02-17-2010, 08:31 AM   #8 (permalink)
New Member
 
Join Date: Feb 2010
Model: 8900
PIN: N/A
Carrier: Dialog
Posts: 6
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here goes my code, as you can see we tried sending the multipart form data byte by byte, in chunks and as a whole.

In the following code the others are commented while sending chunks are kept.

Hope this helps.

The other thing is as I mentioned earlier in WiFi this works fine.

Code:
public String processPOSTRequest(String serviceUrl, String authToken, String itemData, byte[] front, byte[] back) throws ServerException, IOException, InterruptedException {
 HttpConnection httpConnection = null;
 OutputStream dout = null;
 InputStream inputStream = null;
 StringBuffer strBuffer = new StringBuffer();
 String response = "";

 String url = serviceUrl;

 byte[] postBytes = null;

 try {

     String endBoundary = "\r\n--" + BOUNDARY + "--\r\n";

     ByteArrayOutputStream bos = new ByteArrayOutputStream();

     Hashtable params = new Hashtable();
     params.put("Item", itemData);

     bos.write(getBodyMessage(BOUNDARY, params, "Front", "test.jpg", front, "Back", "test2.jpg", back, "image/jpg"));
     bos.write("\r\n".getBytes());
     bos.write(endBoundary.getBytes());

     postBytes = bos.toByteArray();

     bos.close();
     httpConnection = (HttpConnection) Connector.open(url.concat(getAPN()));

     String auth = new String(Base64.encodeBase64(authToken.getBytes()));
     httpConnection.setRequestProperty("Authorization", auth);
     httpConnection.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + BOUNDARY);
     httpConnection.setRequestProperty("Content-Length", Integer.toString(postBytes.length));
     httpConnection.setRequestProperty(HttpProtocolConstants.HEADER_EXPECT, "100-continue");
     httpConnection.setRequestProperty(HttpProtocolConstants.HEADER_CONNECTION, "Keep-Alive");
     httpConnection.setRequestMethod(HttpConnection.POST);
     dout = httpConnection.openOutputStream();

     // TODO :- sending the data byte by byte
    /*
     for (int i = 0; i < postBytes.length; i++) {
  byte[] array = new byte[] { postBytes[i] };
  dout.write(array);
     }
     */
     /*
      * TODO :- sending the data chunk by chunk ByteArrayInputStream
      */
     ByteArrayInputStream array = new ByteArrayInputStream(postBytes);
     byte[] data = new byte[256];
     int len = 0;
     while (-1 != (len = array.read(data))) {
  dout.write(data, 0, len);
     }
      
     /*
      * TODO :- sending the full at once.
      */
     //dout.write(postBytes);


     dout.close();
     int responseCode = httpConnection.getResponseCode();
     if (responseCode != 200) {
  ServerException getErrorExceptions = new ServerException(responseCode, httpConnection.getResponseMessage());
  throw getErrorExceptions;
     }
     

     inputStream = httpConnection.openInputStream();

     int character;

     while (-1 != (character = inputStream.read())) {
  strBuffer.append((char) character);
     }

     response = strBuffer.toString();

 } finally {

     try {
  if (dout != null) {
      dout.close();
  }
     } catch (Exception e) {
     }
     try {
  if (inputStream != null) {
      inputStream.close();
  }
     } catch (IOException e) {

     }

     try {
  if (httpConnection != null) {
      httpConnection.close();
  }
     } catch (IOException e) {

     }
     httpConnection = null;
     inputStream = null;
     dout = null;

     //Utility.displayerrora(num);
 }
 return response;
    }
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





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