×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Jul 2004
    Posts
    3

    MIDlet upload photo problem

    Hi all, I am developing a MIDlet which allows the user to take a photo add some text and then upload it to a servlet.
    My problem is with uploading.
    I upload
    an Integer
    A string
    size of photo byte[]array
    photo

    I can upload the first 3 no problem but not all the bytes for the photo seem to be received by the servlet..

    My code for the MIDlet is

    String job_No = Integer.toString(upJobNo);
    String picString = new String(upLoadImage);
    int picSize = upPicture.length;
    String size = Integer.toString(picSize);


    String allData = job_No+"&"+upPicNotes+"&"+size+"&"+picString;
    byte[] dataToSend = allData.getBytes();

    String dataLength = Integer.toString(allData.length());

    c = (HttpConnection)Connector.open(url2, Connector.READ_WRITE, true);
    c.setRequestMethod(HttpConnection.POST);
    c.setRequestProperty("IF-Modified-Since", "20 Jan 2001 16:19:14 GMT");
    c.setRequestProperty("User-Agent",
    "Profile/MIDP-1.0 Configuration/CLDC-1.0");
    c.setRequestProperty("content-type", "multipart/form-data; " );
    c.setRequestProperty("Content-Length", dataLength);
    c.setRequestProperty("Content-Language", "en-CA");

    os = c.openOutputStream();

    os.write(allData.getBytes());

    os.flush();

    and my servlet code is....


    int dataLength = request.getContentLength();

    BufferedReader br = request.getReader();

    String allData = "";

    try
    {
    String data= "";
    while((data = br.readLine()) != null)
    {
    allData = allData + data;
    }
    }
    finally{br.close();}

    I then seperate the String into the individual parts again, and there is never the full bytes for the photo..
    What am I doing worng??

    also the request.getContentLength() returns -1.

    Any help will be appreciated.
    Thanks in advance.

  2. #2
    Registered User
    Join Date
    Sep 2005
    Posts
    2

    Re: MIDlet upload photo problem

    Hi Kmcgivern,
    I am with a similar problem. could you send me its complete code for me to analyze, MIDLet and Servlet?
    Thanks. Clésio de Miranda.
    e-mail: clesiodemiranda@yahoo.com.br

  3. #3
    Registered User
    Join Date
    Sep 2008
    Posts
    1

    Re: MIDlet upload photo problem

    Hi Kmcgivern,
    I think i can help. I know the way to upload multipart (image...) data to mysql database using php, and how to download that from mysql. after downloding u can append the image to an web site. If u can send me ur codings, i think i can make it work and send u the completed work.

    here's my email : rronyyy@yahoo.com

  4. #4
    Regular Contributor
    Join Date
    Jul 2003
    Posts
    89

    Re: MIDlet upload photo problem

    have a look at this example on Forum Nokia Wiki,

    http://wiki.forum.nokia.com/index.ph...load_with_J2ME

    As for storing it in the Database you can either store the image itself as a blob or simply store the path to the image as text.

Posting Permissions

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