×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Aug 2009
    Posts
    1

    Out of Memory Error uploading large files

    Hi,

    I am working on an application for uploading large files from S60 and got stuck with an Out of Memory error when working with files larger than 8 megabytes.
    The problem is basically the same reported in this old thread.
    Event though I try to upload the file in small chunks, it seems like OutputStream returned from HttpConnection buffers data written into it instead of sending it as it is written until the app is out of memory. I have also tried to flush after every write but it did not make any difference.
    My code is very similar to the one below and it works well even for giant 100 megabytes files on sony ericsson phones.
    Can anyone help?

    Code:

    Code:
    // opening the file connection and inputstream
    fc = (FileConnection)Connector.open("file:///somefile", Connector.READ);
    is = fc.openInputStream();
    
    // opening http connection and outputstream
    HttpConnection http = (HttpConnection)Connector.open(url, Connector.WRITE);
    http.setRequestMethod(HttpConnection.POST);
    http.setRequestProperty("User-Agent", "Profile/MIDP-2.0 Configuration/CLDC-1.1");
    http.setRequestProperty("Content-Type", type);
    http.setRequestProperty("Connection", "close");
    
    OutputStream os = http.openOutputStream();
    
    // algorithm that will read 1024 bytes at a time in 200k packages
    for (int i = startBytes; i < endBytes; i += packetSize) {      
    byte b[] = new byte[1024];
         if ((i + packetSize) < fileSize) {
        int length = is.read(b, 0, packetSize);
         } else {
        int left = (int)fileSize - i;
        int length = is.read(b, 0, left);
         }
    
    // writing into the output stream - these lines will cause the "memory leak", without these, it will not happen
         os.write(b);
    }
    os.flush();
    
    // closing stuff that I have tried
    int rc = http.getResponseCode();
    os.close();
    //os.write(Integer.toString(rc).getBytes());
    http.close();
    System.gc();

  2. #2
    Super Contributor
    Join Date
    Sep 2008
    Location
    Noida, U.P.
    Posts
    1,330

    Thumbs up Re: Out of Memory Error uploading large files

    try to upload the data byte by byte or in chunks. free the memory after writing of each chunk.
    thanks,
    jitu_goldie..

    KEEP TRYING..

  3. #3
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,087

    Re: Out of Memory Error uploading large files

    Try it by closing and opening new connection after sending 8MB of data and do modifiy your server to support this way of reciving large files in chunks of 8MB each in multiple http calls.

    thanks,
    ~Amitabh
    http://www.impetus.com/mlabs/applications.html

Similar Threads

  1. Memory management with audio files
    By lezioul in forum Mobile Java Media (Graphics & Sounds)
    Replies: 8
    Last Post: 2008-03-04, 18:06
  2. Parsing Large XML Files
    By sandordornbush in forum Symbian
    Replies: 11
    Last Post: 2008-01-03, 10:00
  3. Problem downloading large files using HTTP/GET
    By Tjaff in forum Symbian Networking & Messaging (Closed)
    Replies: 2
    Last Post: 2005-06-30, 07:41
  4. Replies: 1
    Last Post: 2004-01-13, 23:16
  5. Can not send large files through Bluetooth
    By sami_masad in forum Bluetooth Technology
    Replies: 0
    Last Post: 2003-08-04, 13:51

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×