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
Contributor
Posts: 31
Registered: ‎03-15-2013
My Device: 9320
My Carrier: Telkomsel
Accepted Solution

Blackberry BrowserField: Application crashes during upload.

[ Edited ]

Hi, i'm using browserfield2 in my application to load webpages, now the problem is the application is always unexpectedly crashes during upload, no problem to upload file with size < 500kb but if the file has >= 1mb size it will crash, the weird thing is i can get uploading process completed with build in Blackberry Browser, hmm... any solution guys? thanks in advance

 

here's the code

    public BrowserDemoScreen()

    {
        setTitle("BrowserFieldScreen");
        BrowserFieldConfig config = new BrowserFieldConfig();
        config.setProperty(BrowserFieldConfig.USER_AGENT, "MyApplication 1.0");
        BrowserField _bf2 = new BrowserField(config);
        
        _bf2 = new BrowserField();
        _bf2.requestContent("http://mydomain/upload.php");
        add(_bf2);
    }

 

html form

 

<form name="upload" enctype="multipart/form-data" method="POST" action="upload.php">
<input type="file" name="uploadfile" size="13"><br>
<input type="submit" name="upload" value="Upload">
</form>

 

php code

 

<?php
$uploaddir = './uploads/';
$filename = $_FILES['uploadfile']['name'];
$filesize = $_FILES['uploadfile']['size'];
$filetemp = $_FILES['uploadfile']['tmp_name'];
$file = $uploaddir . basename($_FILES['uploadfile']['name']);

echo $filename."<br>";
echo $filesize."<br>";
echo $filetemp;

if (move_uploaded_file($filetemp, $file))
{
    echo "success";
}
else
{
    echo "error";
}
?>

 

as you can see i didn't use any javascript on that page, it's pure php, what makes the BrowserField crash?

 

Contributor
Posts: 31
Registered: ‎03-15-2013
My Device: 9320
My Carrier: Telkomsel

Re: Blackberry BrowserField: Application crashes during upload.

[ Edited ]

i tried to make a custom upload screen instead of Browser upload, but doesn't work either

 

package createfileapp;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;

import net.rim.device.api.io.http.HttpProtocolConstants;
import net.rim.device.api.system.Application;

public class PostFile
{
static final String BOUNDARY = "----------V2ymHFg03ehbqgZCaKO6jy";
byte[] postBytes = null;
String url = null;

public PostFile(String url, String fileField, String fileName, String fileType, byte[] fileBytes) throws Exception
{
this.url = url;
String boundary = getBoundaryString();
String boundaryMessage = getBoundaryMessage(boundary, fileField, fileName, fileType);
String endBoundary = "\r\n--" + boundary + "--\r\n";
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bos.write(boundaryMessage.getBytes());
bos.write(fileBytes);
bos.write(endBoundary.getBytes());
this.postBytes = bos.toByteArray();
bos.close();
}

String getBoundaryString()
{
return BOUNDARY;
}

String getBoundaryMessage(String boundary, String fileField, String fileName, String fileType)
{
StringBuffer res = new StringBuffer("--").append(boundary).append("\r\n");
res.append("Content-Disposition: form-data; name=\"").append(fileField).append("\"; filename=\"").append(fileName).append("\"\r\n")
.append("Content-Type: ").append(fileType).append("\r\n\r\n");
return res.toString();
}

public byte[] send(byte[] fileBytes) throws Exception
{
HttpConnection hc = null;
InputStream is = null;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] res = null;
try
{
hc = (HttpConnection) Connector.open(url);
hc.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + getBoundaryString());
hc.setRequestMethod(HttpConnection.POST);
hc.setRequestProperty(HttpProtocolConstants.HEADER_ACCEPT_CHARSET, "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
hc.setRequestProperty(HttpProtocolConstants.HEADER_CONTENT_LENGTH , Integer.toString(fileBytes.length));
OutputStream dout = hc.openOutputStream();
dout.write(postBytes);
dout.close();
int ch;
is = hc.openInputStream();
if(hc.getResponseCode()== HttpConnection.HTTP_OK)
{
synchronized(Application.getEventLock()) {
System.out.println("Response Code : HTTP_OK!");
}
while ((ch = is.read()) != -1)
{
bos.write(ch);
}
res = bos.toByteArray();
//System.out.println("res loaded..");
}
}
catch(IOException e)
{
e.printStackTrace();
synchronized(Application.getEventLock()) {
    System.out.println("====IOException82-1 : "+e.getMessage());
}
}
catch(Exception e1)
{
e1.printStackTrace();
synchronized(Application.getEventLock()) {
    System.out.println("====Exception89-1 : "+e1.getMessage());
}
}
finally
{
try
{
if(bos != null)
bos.close();

if(is != null)
is.close();

if(hc != null)
hc.close();
}
catch(Exception e2)
{
e2.printStackTrace();
synchronized(Application.getEventLock()) {
    System.out.println("====Exception109-1 : "+e2.getMessage());
}
}
}
return res;
}
}

 

it returns the following error

====IOException82-1 : APN is not specified.
Server Response : null

 

 

Contributor
Posts: 31
Registered: ‎03-15-2013
My Device: 9320
My Carrier: Telkomsel

Re: Blackberry BrowserField: Application crashes during upload.

the following log shows why browserfield crash

 

[24941.271] VM:+GC(f)w=11
[24942.203] VM:-GCt=119,b=1,r=0,g=f,w=11,m=0
[24942.264] VM:QUOT t=8
[24942.264] VM:+CR
[24942.287] VM:-CR t=3
[24943.78] Bridge Type: 5 PID: 149 Exception loading URL: net.rim.device.internal.bridge.BridgeDatagramTooLarge[24943.78] Exception: Bridge Datagram size: 8295740 exceeds maximum: 1048576
[24943.78] AM: Exit net_rim_bb_browser_olympia_proxy(397)
[24943.78] Process net_rim_bb_browser_olympia_proxy(397) cleanup started
[24943.78] Bridge Type: 5 PID: 149 Java process cleanup run
[24943.787] VM:EVTOv=7680,w=201
[24943.787] Bridge Type: 5 PID: 149 disconnect
[24943.787] Bridge Type: 5 PID: 149 uninit
[24943.797] Bridge Type: 7 PID: 149 Java process cleanup run
[24943.805] Bridge Type: 7 PID: 149 disconnect
[24943.812] Bridge Type: 7 PID: 149 uninit
[24943.812] Bridge Type: 5 PID: 149 uninit

anyone have any solution for the problem?

Contributor
Posts: 31
Registered: ‎03-15-2013
My Device: 9320
My Carrier: Telkomsel

Re: Blackberry BrowserField: Application crashes during upload.

The solution is:

 

public class Resignation against UiApplication

{

    public Resignation()

    {

        if (fileSize >= 1mb)

            Dialog.alert(" use your personal desktop computer to upload selected file! ");

        else

            Dialog.alert(" good boy, now you understand we have maximum file upload size limit ");

        close();

    }

}