×

Discussion Board

Results 1 to 13 of 13

Hybrid View

  1. #1
    Regular Contributor
    Join Date
    Oct 2008
    Posts
    121

    Sending File to Server using HttpConnection

    Hi All,

    I have J2ME Client, Apache Tomcat Server 5.5. I am able to send file from J2ME Client to server upto certain limit. But once that limit crosses, i get OutOfMemory error. I did search on forum. One link. There were some more. They were talking about sending data in chunks.

    I tried to get all data in ByteArrayOutputStream. - But when i write on dataOutputStream.write(byteArrayOutputStream.toByteArray()). Got OutofMemory error.

    I tried sending one by one byte

    Code:
    while ((input.read(nextByte, 0, 1)) != (-1)) {
       daos.write(nextByte[0]); //daos is outputstream on httpconnection
    }
    But here one httpConnection is opened and then writing on that gives Symbian OS Error -4 (Not enough memory).

    I tried setting "Transfer Encoding" to "Chunked" - But this gave response from server side : java.io.IOException: Invalid chunk header.

    One way could be opening the HttpConnection again and again for each chunk of data and appending that on server side. So open httpconnection - Send Chunk - close connection. But is it advisable to open the httpconnection again and again and sending chunk of data. Or we have some way to open the connection once and then send the chunk of data.

    Just for test i tried to send the stream of data in respose of servlet. It was able to send around 8MB of file to client (Didn't try more than that). So receiving file from server is no issue. But sending file is giving issue.

    How to chunk data and send it to server?

    Please guide or give some pointers which could help.

    Thanks,
    Sandeep

  2. #2
    Regular Contributor
    Join Date
    Oct 2008
    Posts
    121

    Re: Sending File to Server using HttpConnection

    Hi All,

    I tried to use flush also.

    Code:
    while ((input.read(nextByte, 0, 1)) != (-1)) {
       daos.write(nextByte[0]); //daos is outputstream on httpconnection
       daos.flush();
    }
    It does not throw OutOfMemory exception but on server only first byte is written. So after flush the data is not getting written.

    Thanks,
    Sandeep

  3. #3
    Regular Contributor
    Join Date
    Oct 2008
    Posts
    121

    Re: Sending File to Server using HttpConnection

    Hi All,

    Tried with Sun Simulator (WTK 2.5.2). There i even tried to send a file of 40MB. It was sucessfully transferred by using os.flush() or even without using os.flush().

    But on S60 3rd Edition FP2 Simulator. os.flush() is just writing first chunk of data. And without using os.flush() it throws OutOfMemory Error.

    Anyone has tried this on S40 simulator?

    I am not understanding how this could be solved. Please give some pointers

    Thanks,
    Sandeep

  4. #4
    Regular Contributor
    Join Date
    Oct 2008
    Posts
    121

    Re: Sending File to Server using HttpConnection

    Hi All,

    Tried on S40 6th Edition Simulator as well. Here also os.flush() is just pushing first chunk of data. and without os.flush() it gives OutOfMemory Error.

    Does it behaves similarly on Device also? I would need Static IP to test it. If any one had done file transfer through phone. Please let us know your observations.

    Will flush() work on device? Or we have to do some thing else to send bigger file?

    Please provide some pointers.

    Thanks,
    Sandeep

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

    Thumbs up Re: Sending File to Server using HttpConnection

    Quote Originally Posted by sandeepkumar03 View Post
    Hi All,

    Tried on S40 6th Edition Simulator as well. Here also os.flush() is just pushing first chunk of data. and without os.flush() it gives OutOfMemory Error.

    Does it behaves similarly on Device also? I would need Static IP to test it. If any one had done file transfer through phone. Please let us know your observations.

    Will flush() work on device? Or we have to do some thing else to send bigger file?

    Please provide some pointers.

    Thanks,
    Sandeep
    Write the data in chunks in outputstream. Make a small chunk of data upto of 100 kb. Do Flush only one time when all the data is written.
    thanks,
    jitu_goldie..

    KEEP TRYING..

  6. #6
    Regular Contributor
    Join Date
    Oct 2008
    Posts
    121

    Re: Sending File to Server using HttpConnection

    Hi Jitu,

    Write the data in chunks in outputstream. Make a small chunk of data upto of 100 kb. Do Flush only one time when all the data is written.
    We would write in chunks like this right

    Code:
    byte[] buffer = new byte[100 * 1024]; // 100 Kb buffer
    while ((input.read(buffer , 0, buffer.length)) != (-1)) {
       daos.write(buffer); //daos is outputstream on httpconnection
    }
    daos.flush();
    This was giving IOException Symbian OS Error -4 (Not enough memory) on S60 simulator. Haven't tested this on device. It might be a simulator problem?

    Thanks,
    Sandeep
    Last edited by sandeepkumar03; 2009-11-09 at 12:06. Reason: Typo

  7. #7
    Regular Contributor
    Join Date
    Oct 2008
    Posts
    121

    Re: Sending File to Server using HttpConnection

    Hi,

    As i kept on researching on this issue. I tried different permutations and combinations.

    Server Issue : I thought it may be server issue. tried with JBoss instead of Tomcat. It seems to be making no difference.

    Open Close Connection and Append Data on Server : This is also one option. As in single connection i am getting Symbain OS Error -4. Got some info related to this on Sending Data in Chunks thread.. In this Amit has mentioned about this. We can append the data on the server side by using FileOutputStream in append mode. Will this cause and issue in case chunk is lost and file might get corrupted?

    Limiting the user for sending files may be till 2 MB : As larger file has problems. Limit user to some size. Is that a good option?

    Device Testing Observations : Tested on E61, E71 both had different behviours. On E71 i was able to send around 4 MB but on S61 got Symbian OS Error -4. Operator also limits sometime. I had Vodafone live GPRS Connection it was not working using that. I had to get VMC enable( Mobile Office in case of Airtel) to make it work. Simple GPRS connection may not allow to send files for certain MIME Type.

    Inputs on file transfer to server would help.

    Thanks,
    Sandeep

Similar Threads

  1. MBM image is not found
    By tamhanna in forum Symbian
    Replies: 14
    Last Post: 2009-04-20, 12:44
  2. How to handle UI, server connection and file handling in MIDP application for 6630?
    By SanjayKhuntia in forum Mobile Java Networking & Messaging & Security
    Replies: 1
    Last Post: 2008-09-19, 08:36
  3. Contacts fields order??
    By timatima in forum Symbian
    Replies: 1
    Last Post: 2007-06-08, 13:51
  4. Sending file via GPRS
    By minou in forum Mobile Java Networking & Messaging & Security
    Replies: 3
    Last Post: 2006-09-17, 18:32

Posting Permissions

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