×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Regular Contributor
    Join Date
    May 2009
    Posts
    52

    Http uploading problem

    hi,
    i am trying to upload vedeo data to server by spliting in different pieces.but its working fine in emulator the problem is it is not wrking in mobile.please suggest any idea regarding this problem.i have tested application in 6120 classic phone.while uploading data size less than 1 mB working fine.and i am not getting any error while uploading .The code i have used give below,

    Code:
      public String  SplitProcess(String Title, String Descr, String Tag, String Category, String Type, String Permission, String FileName, String FileExtn,String OpenFile) throws IOException
        {
             byte imgdata[] ;
         stringManipulation str = new stringManipulation();
            String defaultURL  = "http://dev.mobile.in/j2me_index.php";
                       
                            
          
          
              try {
                    
                FileConnection fc=(FileConnection)Connector.open(OpenFile);
                System.out.println("fc.fileSize()= " + fc.fileSize());
                DataInputStream din=(DataInputStream)fc.openDataInputStream();
                int ch;
                ByteArrayOutputStream bytearray = new ByteArrayOutputStream();
                
                  int index = 1;
                while ((ch = din.read()) != -1) 
                {
                   bytearray.write(ch) ;
                   
                     if(bytearray.size() > 1000000) 
                     {
                         imgdata = bytearray.toByteArray(); 
                        String  filenamewithoutextension= str.getFileName(FileName) + index +"."+FileExtn;
                        UploadSecond uploadSecond = new UploadSecond();
    //function for uploading 
                        String res= uploadSecond.UploadingFiles(imgdata,filenamewithoutextension,FileExtn,defaultURL) ;    
                        index++ ;
                        bytearray.reset();
                                                            
                      } 
               }
                 imgdata = bytearray.toByteArray(); 
             
            //  String FName = FileName+index ;
                String  filenamewithoutextension= str.getFileName(FileName) + index +"."+FileExtn;
               // UploadSecond uploadSecond = new UploadSecond();
                String res=  UploadingFiles(imgdata,filenamewithoutextension,FileExtn,defaultURL) ;  
              
                din.close();
                fc.close();
                
            } catch (Error e2) {
                
           
              return  "failed" ;
           }
         
              return "sucess" ;
                  
        } 
      public String  UploadingFiles(byte imgvideo[],String FileName,String FileExtn,String URL) throws IOException
        {
           
            byte imgdata[] = imgvideo ;
            StringBuffer responseMessage = new StringBuffer();
            String uploadResult;
            uploadResult="";
            HttpConnection hpc = null;
            DataInputStream dis = null;
            DataOutputStream dos = null;
            String defaultURL;
            boolean newline = false;
            String content = "";
            
              try {
                
              
                
                HttpConnection con=(HttpConnection)Connector.open(URL);
                con.setRequestMethod(HttpConnection.POST);
                
                con.setRequestProperty("User-Agent","Profile/MIDP-1.0 Confirguration/CLDC-1.0");
                con.setRequestProperty("Accept_Language","en-US");
                //Content-Type is must to pass parameters in POST Request
                con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
                con.setRequestProperty("Content-Length",""+ ("sss".length()));
                
              //  if (con.getResponseCode() != HttpConnection.HTTP_OK) {
                    
                   // Alert ErrorCon = new Alert("Network Status","Unable to connect...",null,AlertType.INFO);
                  //  ErrorCon.setTimeout(Alert.FOREVER);
                   // display.setCurrent(ErrorCon);
                    
              //  } else {
                    
                    String message1 = "";
                    message1 += "-----------------------------4664151417711" + CrLf;
                    message1 += "Content-Disposition: form-data; name=\"sreehari\"; filename=\"" + FileName + "\"" + CrLf;
                    message1 += "Content-Type:"+FileExtn+" "+ CrLf;
                    message1 += CrLf;
                    String message2 = "";
                    message2 += CrLf + "-----------------------------4664151417711--" + CrLf;
                    con.setRequestProperty("Content-Type", "multipart/form-data; boundary=---------------------------4664151417711");
                    dos=con.openDataOutputStream();
                    dos.write(message1.getBytes());
           
                         do 
                         {
                           System.out.println("write:" + index);
                           if((index+size)>imgdata.length)
                           {
                                System.out.println("insideeeeeeeee  dddd") ;
                                size = imgdata.length - index;
                           }
                           dos.write(imgdata, index, size);
                           index+=size;
                           }while(index<imgdata.length); 
                   
                    
                    
                
                    
                    dos.write(message2.getBytes());
                    System.out.println("rtttttttttttttttt ::") ;  
                    dis = con.openDataInputStream();
                    System.out.println("rtttttttseconddddddddtt ::") ;  
                    int chz;
                     while( (chz = dis.read() ) != -1 ) 
                     {
                       responseMessage.append( (char)chz );
                     }
                    System.out.println("DONE");
                    dos.flush();
                    dos.close();
                    dis.close();
                    con.close();
                  
            } catch (Error e2) {
                
              e2.getMessage();
              return  e2.getMessage().toString();
           }
              System.out.println("Response ::::::"+responseMessage.toString());
              
              return responseMessage.toString();
                  
        }

  2. #2
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: Http uploading problem

    In what way is it "not working"? Can you be more specific?

    I'd suggest you find out if any Exceptions are being thrown (or Errors, since you're catching them and not doing anything with them). Also, it might be interesting to know if there is a response code from the server.

    Graham.

Similar Threads

  1. HTTP Problem
    By pv123 in forum Symbian Networking & Messaging (Closed)
    Replies: 3
    Last Post: 2009-11-25, 11:27
  2. problem with Http response head
    By yang_xixiang in forum Symbian
    Replies: 1
    Last Post: 2009-11-02, 18:59
  3. Replies: 2
    Last Post: 2003-02-19, 03:10

Posting Permissions

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