Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6974915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:17:58+00:00 2026-05-27T17:17:58+00:00

I want to upload a file to net server use the codes. but when

  • 0

I want to upload a file to net server use the codes. but when the size > 6M ,throw a FATAL EXCEPTION java.lang.OutOfMemoryError

    HttpURLConnection conn;
    URL url = new URL(mServerUrl);
    conn = (HttpURLConnection) url.openConnection();
    conn.setDoOutput(true);
    conn.setDoInput(true);
    conn.setUseCaches(false);
    conn.setRequestMethod("POST");
    conn.setRequestProperty("Content-Type", file.getContentType());
    conn.setRequestProperty("Connection", "close");
    conn.setRequestProperty("Charset", "UTF-8");
    conn.connect();
    DataOutputStream os = new DataOutputStream(conn.getOutputStream());

    int totalSize = 0;
    byte[] buffer = new byte[1024];
    int len = 0;
    while ((len = file.getInStream().read(buffer, 0, 1024)) != -1) {

        totalSize += len;
        WDLog.i("totalSize = " + totalSize);
        os.write(buffer, 0, len);

    }

    file.getInStream().close();
    os.flush();
    os.close();

what could i do to solve the question??
thanks

there are logcat infos:

12-26 19:35:06.976: D/dalvikvm(8952): GC_FOR_MALLOC freed 36718 objects / 1675552 bytes in 53ms
12-26 19:35:06.976: I/dalvikvm-heap(8952): Forcing collection of SoftReferences for 12580880-byte allocation
12-26 19:35:07.006: D/dalvikvm(8952): GC_FOR_MALLOC freed 646 objects / 47808 bytes in 34ms
12-26 19:35:07.006: E/dalvikvm-heap(8952): Out of memory on a 12580880-byte allocation.
12-26 19:35:07.006: I/dalvikvm(8952): "Thread-29" prio=5 tid=8 RUNNABLE
12-26 19:35:07.006: I/dalvikvm(8952):   | group="main" sCount=0 dsCount=0 s=N obj=0x46230978 self=0x30eb98
12-26 19:35:07.006: I/dalvikvm(8952):   | sysTid=8980 nice=0 sched=0/0 cgrp=default handle=3159096
12-26 19:35:07.016: I/dalvikvm(8952):   | schedstat=( 5075164776 7730011023 9520 )
12-26 19:35:07.016: I/dalvikvm(8952):   at java.io.ByteArrayOutputStream.expand(ByteArrayOutputStream.java:~93)
12-26 19:35:07.016: I/dalvikvm(8952):   at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:218)
12-26 19:35:07.016: I/dalvikvm(8952):   at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl$DefaultHttpOutputStream.write(HttpURLConnectionImpl.java:750)
12-26 19:35:07.016: I/dalvikvm(8952):   at java.io.DataOutputStream.write(DataOutputStream.java:101)
12-26 19:35:07.016: I/dalvikvm(8952):   at com.amtcmv.upload.UploadImgVidFile.postVid(UploadImgVidFile.java:218)
12-26 19:35:07.016: I/dalvikvm(8952):   at com.amtcmv.upload.UploadImgVidFile.run(UploadImgVidFile.java:95)
12-26 19:35:07.016: I/dalvikvm(8952):   at java.lang.Thread.run(Thread.java:1102)
12-26 19:35:07.016: E/dalvikvm(8952): Out of memory: Heap Size=19783KB, Allocated=9352KB, Bitmap Size=162KB
12-26 19:35:07.016: W/dalvikvm(8952): threadid=8: thread exiting with uncaught exception (group=0x400259f8)
12-26 19:35:07.026: E/AndroidRuntime(8952): FATAL EXCEPTION: Thread-29
12-26 19:35:07.026: E/AndroidRuntime(8952): java.lang.OutOfMemoryError
12-26 19:35:07.026: E/AndroidRuntime(8952):     at java.io.ByteArrayOutputStream.expand(ByteArrayOutputStream.java:93)
12-26 19:35:07.026: E/AndroidRuntime(8952):     at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:218)
12-26 19:35:07.026: E/AndroidRuntime(8952):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl$DefaultHttpOutputStream.write(HttpURLConnectionImpl.java:750)
12-26 19:35:07.026: E/AndroidRuntime(8952):     at java.io.DataOutputStream.write(DataOutputStream.java:101)
12-26 19:35:07.026: E/AndroidRuntime(8952):     at com.amtcmv.upload.UploadImgVidFile.postVid(UploadImgVidFile.java:218)
12-26 19:35:07.026: E/AndroidRuntime(8952):     at com.amtcmv.upload.UploadImgVidFile.run(UploadImgVidFile.java:95)
12-26 19:35:07.026: E/AndroidRuntime(8952):     at java.lang.Thread.run(Thread.java:1102)

and at

os.write(buffer, 0, len);

this line throw the error.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T17:17:59+00:00Added an answer on May 27, 2026 at 5:17 pm

    Upload the file to the server in chunk by chunk basis. example. first upload 1024 bytes of data after getting response from server upload the next 1024 bytes of data and so on until the all the data of the file is uploaded.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to upload the sound file (.ogg) in server. But it should write
I want upload file without reload page. My server-side is ASP.NET MVC. Ext.Ajax.request( {
I want to upload a file to a ftp server programmatically (C++). If the
In Flex i want to upload a particular file to server form local system.how
I use the PHP language for file upload and want to know that the
asp.net provides file upload control.... now if i want to upload files on my
I am trying to upload files to a web server using System.Net.WebClient.UploadFile but I
I want to use https to upload a file using WebClient's UploadData method. And
I want my customers to upload some file to my server. My current design
I am a newbie in ASP.NET and html. I want to upload a file,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.