Football Fans: Download the 2012 Schedule App from Google Play!


Go Back   Android Forums > Android Discussion > Android Applications

Android Applications All the information you could ever want about Android Applications. Learn about apps and get help with them... all here! New apps can be found and announced in the Applications Announcements forum linked below.



Reply
 
LinkBack Thread Tools
Old June 29th, 2009, 11:03 PM   #1 (permalink)
New Member
 
Join Date: Jun 2009
Posts: 4
 
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
Default Error uploading audio Files

hello,

i m trying to upload more than one audio Files, having size more than 4 mb each.
but i m getting this exception

06-29 18:22:40.739: ERROR/AndroidRuntime(727): Uncaught handler: thread Thread-9 exiting due to uncaught exception
06-29 18:22:40.751: ERROR/AndroidRuntime(727): java.lang.OutOfMemoryError
06-29 18:22:40.751: ERROR/AndroidRuntime(727): at java.io.ByteArrayOutputStream.expand(ByteArrayOutp utStream.java:103)
06-29 18:22:40.751: ERROR/AndroidRuntime(727): at java.io.ByteArrayOutputStream.write(ByteArrayOutpu tStream.java:234)
06-29 18:22:40.751: ERROR/AndroidRuntime(727): at org.apache.harmony.luni.internal.net.www.protocol. http.HttpURLConnection$HttpOutputStream.write(Http URLConnection.java:652)
06-29 18:22:40.751: ERROR/AndroidRuntime(727): at java.io.DataOutputStream.write(DataOutputStream.ja va:107)


The code i use for uploading files is :

privateboolean uploadFile(File file, String urlString) {

boolean isUploadOk = false;
HttpURLConnection conn = null;
DataOutputStream dos = null;
FileInputStream fileInputStream = null;

int maxBufferSize = 4096;

try {

// Open a HTTP connection to the URL
URL url = new URL(urlString);
conn = (HttpURLConnection) url.openConnection();

// Allow Inputs
conn.setDoInput(true);
// Allow Outputs
conn.setDoOutput(true);
// Don't use a cached copy.
conn.setUseCaches(true);
// Use a post method.
conn.setRequestMethod("PUT");
conn.setRequestProperty("Connection", "Keep-Alive");

conn.setRequestProperty("Content-Type",
"multipart/form-data;boundary=" + boundary);

dos = new DataOutputStream(conn.getOutputStream());
dos.writeBytes(twoHyphens + boundary + lineEnd);
dos.writeBytes("Content-Disposition: form-data; name=\""
+ file.getAbsolutePath() + "\";filename=\""
+ file.getName() + "\"" + lineEnd);
dos.writeBytes(lineEnd);

Log.e("", "Headers are written");

// create a buffer of maximum size
fileInputStream = new FileInputStream(file);
int bytesAvailable = fileInputStream.available();
int bufferSize = Math.min(bytesAvailable, maxBufferSize);

byte[] buffer = newbyte[bufferSize];

// read file and write it into form...
int bytesRead = fileInputStream.read(buffer, 0, bufferSize);

while (bytesRead > 0) {
dos.write(buffer, 0, bufferSize);
bytesAvailable = fileInputStream.available();
bufferSize = Math.min(bytesAvailable, maxBufferSize);
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
dos.flush();
}

buffer = null;

// send MULTIPART/FORM data necessary after file data.!
dos.writeBytes(lineEnd);
dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);

// close streams
Log.e("fileupload", "File is written");


} catch (MalformedURLException ex) {
Log.e("fileupload", "error: " + ex.getMessage(), ex);
}
catch (IOException ioe) {
Log.e("Exception:: ", "error: " + ioe.getMessage(), ioe);

}finally
{
try
{
if(fileInputStream != null)
fileInputStream.close();

}catch (Exception e) {

}

try
{
if(dos != null)
{
dos.flush();
//dos.close();
}

}catch (Exception e) {

}

try
{
if(dos != null)
{

dos.close();
}

}catch (Exception e) {

}

}



return isUploadOk;
}





vikram.patil is offline  
Reply With Quote
Sponsors
Reply

Bookmarks


Go Back   Android Forums > Android Discussion > Android Applications User CP
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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Uploading files chrlswltrs Android Applications 2 August 20th, 2010 11:43 AM
Support Uploading files to forums Dem Sony Ericsson Xperia X10 0 April 23rd, 2010 04:00 PM
Uploading files vintek Android Applications 0 December 11th, 2009 12:03 PM
PHP Error When Uploading Avatar Gremlyn1 Suggestion Box & Feedback 3 November 5th, 2009 02:56 PM
Error uploading audio Files vikram.patil Application Development 0 June 29th, 2009 11:02 PM



All times are GMT -5. The time now is 09:18 PM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Custom vBulletin Skins by: Relivo