×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    18

    Problem with posting data to the server.

    hello all..

    I am trying to upload a file to our server. My code works properly with small sized files, but it is giving problem while uploading a larger sized files. its giving "java/lang/OutOfMemoryError." error. I suppose if there is any restriction in the size that we upload the data in our "GFC" after debuging i think it may be "ByteArrayOutputStream" which is making problem, i am not sure. so please can anybody tel me are there any restrictions as such.

    my code is like this..

    InputStream input = fileConnection.openInputStream();
    ByteArrayOutputStream out = new ByteArrayOutputStream();

    int read;
    byte[] buffer = new byte[1024];
    while ((read = input.read(buffer,0,1024)) != -1) {
    out.write(buffer, 0, read);
    }
    System.out.println("after while.......");
    byte[] data = out.toByteArray();
    input.close();

    // all works fine but if larger file selected then memory error comes before the "after while" print statement. ( also i am not getting exact file size limit, i am able to send 3 MB of data.. but file size of 5MB is not been sent..

  2. #2
    Nokia Developer Champion
    Join Date
    Nov 2007
    Location
    Rome, Italy
    Posts
    2,405

    Re: Problem with posting data to the server.

    Hi chetubc,

    an OutOfMemoryError exception means that you're using more than the available Java heap memory.

    In your code, you're reading the whole file and putting its data into a ByteArrayOutoutStream: to avoid this, and so your memory problem, you could try reading small chunks of your file and immediatly writing them into your HTTP connection OutputStream, so avoiding storing all file content in memory.

    Hope it helps,
    Pit

  3. #3
    Registered User
    Join Date
    Sep 2007
    Location
    Bangalore
    Posts
    868

    Re: Problem with posting data to the server.

    Hi,
    What Pit Saying is Exactly Correct. Any way you are reading the 1KB data and putting in to ByteArrayOutputstream . When ever you read 1KB data you rather than putting in to ByteBuffer , Put that on http output steam at last on ending of the while loop flush the http outpust steam . I think this will solve your problem

  4. #4
    Registered User
    Join Date
    Apr 2008
    Posts
    18

    Re: Problem with posting data to the server.

    thank u very much jappit & bhanuchandar,
    the issue resolved.
    chetubc

  5. #5
    Registered User
    Join Date
    Apr 2008
    Posts
    18

    Re: Problem with posting data to the server.

    sorry, this issue seems to exist still.
    i am putting my code here...
    i thought no problem may raise for the code i have, however this is working fine in the emulators, i am able to send a file of size upto 11MB with out any problem but on device, its giving OutOfMemoryError, (tested handsets - Nokia E51 around 11MB it gives error, Nokia N80, around 6MB error comes).


    DataOutputStream os = null;
    os = c.openDataOutputStream();
    InputStream input = fc.openInputStream();

    int read;
    byte[] buffer = new byte[1024];
    while ((read = input.read(buffer, 0, 1024)) != -1) {
    os.write(buffer);
    }

    os.flush();
    os.close();

    where, c is HttpConnection opened with my server,
    & fc is FileConnection for my file.

    please let me know whats going wring here.
    thanks in advance,
    chetan.

Similar Threads

  1. How to send mobile file data to Server on Nokia 6630?
    By SanjayKhuntia in forum Symbian
    Replies: 1
    Last Post: 2008-08-25, 11:26
  2. 6085: packet data problem when connect ot server
    By hartti in forum Mobile Java Networking & Messaging & Security
    Replies: 0
    Last Post: 2007-07-26, 23:06
  3. problem in uploading the data from MIDLet to server
    By hsjha in forum Mobile Java General
    Replies: 1
    Last Post: 2004-01-06, 09:46
  4. posting data from 9210 web browser back to web server
    By cl_bonesbb in forum Symbian Networking & Messaging (Closed)
    Replies: 1
    Last Post: 2001-12-05, 14: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
  •