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
BlackBerry Development Advisor
Posts: 15,693
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: Download Files

There isn't much you can do from the client side to address the first error of the server not responding.  But here is some information about the second, 413 error.

 

HTTP 413 Request Entity Too Large

http://supportforums.blackberry.com/t5/Java-Development/HTTP-413-Request-Entity-Too-Large/ta-p/44598...

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Developer
Posts: 51
Registered: ‎10-21-2008
My Device: Bold 9000
My Carrier: Dialog

Re: Download Files

[ Edited ]

Dear Mark.

 

I read that article. So please just say something to this question. If I want to download 4 MB MP3 file is it possible or not through blackberry internet connection? It is within that limit even. I am really stuck with this situation.

 

Highly appriciate your kind help.

 

Thank you so much.

 

Prasad.

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Download Files

It is possible to download much larger files than the limit, however you have to do the download in parts, rather than than in one connection.  You can manage this splitting and rejoining yourself if you want, however http 1.1 already provides a mechanism to do this, which is used in this KB article I pointed you too earlier. 

 

http://supportforums.blackberry.com/t5/Java-Development/Download-large-files-using-the-BlackBerry-Mo...

Developer
Posts: 51
Registered: ‎10-21-2008
My Device: Bold 9000
My Carrier: Dialog

Re: Download Files

Hi My Friends,

 

Thank you all for your given support. Finally I could make it by getting fixed amount of bytes at a time. For all others sake here I will put my code.

 

import javax.microedition.io.HttpConnection;
import java.io.InputStream;
import java.io.OutputStream;
import javax.microedition.io.Connector;
import javax.microedition.io.file.FileConnection;

/**
*
*/
class MP3Downloader
{
MP3Downloader()
{

}

public void DownloadFile(String remoteFile, String localfile)
{
int startByte = 0;
int bunchSize = 100000;
try
{
FileConnection dest = (FileConnection)Connector.open(localfile,Connector.READ_WRITE);
if (!dest.exists()) {
dest.create();
}
OutputStream outStream = dest.openOutputStream();

while(true)
{

HttpConnection connection = null;
InputStream inputStream = null;

connection = (HttpConnection) Connector.open(remoteFile, Connector.READ_WRITE, true);

connection.setRequestProperty("Range", "bytes=" + startByte + "-" + ((startByte += bunchSize) -1));
inputStream = connection.openInputStream();

//byte[] data = IOUtilities.streamToBytes(inputStream);
//Dialog.alert(String.valueOf(data.length));

int responseCode = connection.getResponseCode();
if (responseCode != 200 && responseCode != 206)
{
break;
}

byte[] Buffer = new byte[1024];
int length = -1;
while ((length = inputStream.read(Buffer)) > 0) {
outStream.write(Buffer, 0 , length);
}



connection.close();
}
outStream.close();
}
catch ( Exception e )
{

}
}

 

Thank you.

Prasad

Regular Contributor
Posts: 90
Registered: ‎09-16-2010
My Device: Not Specified

Re: Download Files

Hi i'm using the code you posted to  download a .mov file . After the file is successfully downloaded,i directly play the file from the media player of the device, however i get error

The video portion of the media being played uses an unsupported format.

 

Please help