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 6790407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:43:19+00:00 2026-05-26T17:43:19+00:00

While I am uploading the mobile and application number in multipart from-data from mobile

  • 0

While I am uploading the mobile and application number in multipart from-data from mobile it is hitting the server and data is storing in database.Now I added captured image to it and sent to server it is showing an exception.

org.apache.commons.fileupload.FileUploadBase$UnknownSizeException: the request was rejected because its size is unknown
    at org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:305)
    at org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest (ServletFileUpload.java:116)
    at org.apache.jsp.photo_jsp._jspService(photo_jsp.java:103)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:384)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter
(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter
(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:228)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:216)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process (Http11Protocol.java:634)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:445)
    at java.lang.Thread.run(Unknown Source)

Here I am sending Mobile and application Number and captured image in bytes (imagecapturephoto1). Captured image is storing in view after taking photo.But when we are uploading it is showing exception.

try
        {
            System.out.println("url:" + serverUrl);
        connection = (HttpConnection)Connector.open(serverUrl,Connector.READ_WRITE);                          
                connection.setRequestMethod(HttpConnection.POST);

        connection.setRequestProperty("Content-Type", "multipart/form-data; boundary=*****"); 
        connection.setRequestProperty("User-Agent", "Profile/MIDP-2.1 Configuration/CLDC-1.1");
        connection.setRequestProperty("Accept", "application/octet-stream" );

        writer = new DataOutputStream(connection.openDataOutputStream());               
        //  writer =new DataOutputStream( conn.openOutputStream()); 
        String name="applicationNumber", name1="mobileNumber",name3="photo",
                mimeType="text/plain",mimeType2="image/jpeg";

        String value="123456789", value1="9849765432",fileName="applicationphoto.jpeg";
                // write boundary         
                writeString(PREFIX);
                writeString(boundary);
                writeString(NEWLINE);
                // write content header
                writeString("Content-Disposition: form-data; name=\"" + name + "\"");
                writeString(NEWLINE);
                if (mimeType != null) 
                {
                    writeString("Content-Type: " + mimeType);
                    writeString(NEWLINE);
                }
                writeString("Content-Length: " + applicationNumber.length());
                writeString(NEWLINE);
                writeString(NEWLINE);
                // write content
                writeString(applicationNumber);                               
                writeString(NEWLINE);                                        

                // write boundary
                writeString(PREFIX);
                writeString(boundary);                                     
                writeString(NEWLINE);                                    
                // write content header
                writeString("Content-Disposition: form-data; name=\"" + name1 + "\"");
                writeString(NEWLINE);  
                if (mimeType != null) 
                {
                    writeString("Content-Type: " + mimeType);
                    writeString(NEWLINE);
                }
                writeString("Content-Length: " + mobileNumber.length());                
                writeString(NEWLINE);                                                   
                writeString(NEWLINE);                                       
                // write content
                writeString(mobileNumber);                 
                writeString(NEWLINE);  

               //uploading image...........            
              // write boundary
                writeString(PREFIX);                            
                writeString(boundary);      
                writeString(NEWLINE);                                         
                // write content header
                writeString("Content-Disposition: form-data; name=\"" + name3
                        + "\"; filename=\"" + fileName + "\"");
                writeString(NEWLINE);
                if (mimeType2 != null) 
                {
                    writeString("Content-Type: " + mimeType2);
                    writeString(NEWLINE);
                }
                writeString("Content-Length: " + imagecapturephoto1.length);
                writeString(NEWLINE);
                writeString(NEWLINE);                     
                // write content
                // SEND THE IMAGE
                int index = 0;
                int size = 1024;
                do
                {                              
                    System.out.println("write:" + index);
                    if((index+size)<=imagecapturephoto1.length)
                    {
                        writer.write(imagecapturephoto1, index, size);
                    }

                    index+=size;
                }while(index<imagecapturephoto1.length);
                writeString(NEWLINE);


                writeString(PREFIX);
                writeString(boundary);
                writeString(PREFIX);
                writeString(NEWLINE);
                writer.flush();

                //writer.write("-- ***** -- \r\n".getBytes());                
                serverResponseMessage = connection.getResponseMessage();
                InputStream inputstream = connection.openInputStream();
                // retrieve the response from server
                int chnumber;
                StringBuffer sbuffer =new StringBuffer();
                while( ( chnumber= inputstream.read() ) != -1 )
                {
                    sbuffer.append( (char)chnumber );
                }
                String resonsestring=sbuffer.toString(); 
                int end=resonsestring.length();
                int tempstr=resonsestring.indexOf(">");

                statusResponse=resonsestring.substring(tempstr+1, end);
                statusResponse="SUCCESS";
                //outputStream.close();
                writer.close();
                connection.close();
                return serverResponseMessage;
            }
            catch (Exception ex)
            {
                //statusResponse="SUCCESS";
                ex.printStackTrace();
                return null;
            }

Please suggest me,How we have to upload image from mobile.I was struck from last 10 days.please suggest me how to solve this issue.

Thanks in advance.
-Teja.

  • 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-26T17:43:19+00:00Added an answer on May 26, 2026 at 5:43 pm

    kindly try following code segment, Please ignore lat-lon coding.

    private void postImageToServer(String curURL) throws Exception
        {
            // Open up a http connection with the Web server for both send and receive operations
    
                midlet.get_frmLog().append("HttpConnection Enter");
    
                httpConnection = (HttpConnection)Connector.open(URL, Connector.READ_WRITE);
    
                // Set the request method to POST
                httpConnection.setRequestMethod(HttpConnection.POST);
                // Set the request headers
                httpConnection.setRequestProperty(ConstantCodes.ACTION_MODE_PARAMETER,action);
                httpConnection.setRequestProperty(ConstantCodes.USER_NAME_REQUEST_PARAMETER,userName);
    
                //httpConnection.setRequestProperty("lat","22.955804");
                //httpConnection.setRequestProperty("lon","72.685876");
                //httpConnection.setRequestProperty("lat",LatLonFetcherThread.getLatitude());
                //httpConnection.setRequestProperty("lon",LatLonFetcherThread.getLongitude());
    
                /*lat = "23.0172";
                lon = "72.3416";*/
    
                if ( midlet.get_choiceGroupGPS().getSelectedIndex() == 0 )
                {
                    lat = LatLonFetcherThread.getLatitude();
                    lon = LatLonFetcherThread.getLongitude();
                }
                else if ( midlet.get_choiceGroupGPS().getSelectedIndex() != 0 )  // Added By KALPEN
                {
                    if ( midlet.state == mREPORTER.STATE_READING )
                    {
                        double xLat,xLon;
                        try
                        {
                            GpsBt.instance().start();
                            //while (true)
                            {
                                gpsBt = GpsBt.instance();
                                if ( gpsBt.isConnected() )
                                {
                                    location = gpsBt.getLocation();
    
                                    //lat = location.utc;
                                    //lon = location.utc;
    
                                    lat = (location.latitude + location.northHemi);
                                    lon = (location.longitude + location.eastHemi);
    
                                    lat = lat.substring(0,lat.length()-1);
                                    lon = lon.substring(0,lon.length()-1);
    
                                    xLat = Double.parseDouble(lat) / (double)100.00;
                                    xLon = Double.parseDouble(lon) / (double)100.00;
    
                                    lat = xLat + "";
                                    lon = xLon + "";
    
                                    lat = lat.substring(0,7);
                                    lon = lon.substring(0,7);
    
                                    //lat = "23.0172";
                                    //lon = "72.3416";
    
                                }
                                Thread.sleep(100);
                            }
                        }
                        catch  ( Exception e ) { lat = "23.0172"; lon = "72.3416"; }
                    }
                }
    
                httpConnection.setRequestProperty("lat",lat); // Modifed by KALPEN
                httpConnection.setRequestProperty("lon",lon); // Modifed by KALPEN
    
                //String latlongStr = "Latitude: " + LatLonFetcherThread.getLatitude()
                //      + "\nLongitude: " + LatLonFetcherThread.getLongitude();
                /*String latlongStr = "lat: 22.955804" + "lon: 72.685876";*/
    
                //#style screenAlert
                /*Alert latlonAlert = new Alert("LatLon alert" );
                latlonAlert.setString(latlongStr);
                mREPORTER.display.setCurrent(latlonAlert);*/
    
                if(eventName == null || eventName.equals(""))
                    eventName = "default";
    
                // all the headers are sending now and connection channel is establising
                httpConnection.setRequestProperty(ConstantCodes.EVENT_NAME_REQUEST_PARAMETER, eventName);
                httpConnection.setRequestProperty(ConstantCodes.CAMERAID_REQUEST_PARAMETER, cameraID);
                httpConnection.setRequestProperty(ConstantCodes.COMPRESSION_MODE_REQUEST_PARAMETER, compressionMode);
    
    
                midlet.get_frmLog().append("Write on server-->"+imageBytes.length);
    
                DataOutputStream dos = httpConnection.openDataOutputStream();
                dos.write(imageBytes);
                midlet.threadFlag=true;
          }
    

    Above Method works fine with my code, as I am also trying to upload Image to Server.

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

Sidebar

Related Questions

I noticed something while uploading some unicode data to the database. When the content
While uploading images files on the live server I have stuck in a strange
While uploading my current project to our staging server I noticed that the Web.config
recently i came across strange problem while uploading files to my new server. I
anyone know how to add background while uploading data ?, currently performanceprogressbar just shown
While user uploading a file, is it possible to know if the uploaded file
I'm Getting this error in my development log while uploadify is uploading the file
While in the final throws of upgrading MS-SQL Server 2005 Express Edition to MS-SQL
While going through university and from following the development of SO, I've heard a
While setting up CruiseControl, I added a buildpublisher block to the publisher tasks: <buildpublisher>

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.