×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Jun 2010
    Posts
    2

    [ask] upload files from J2ME to PC server?

    hi...
    im trying to upload file (audio file *.wav) from mobile to server. i'm using HttpConnenction. my file are on local device so i'm using fileconnection to. can anyone help me?? i'm really need this code, please help me...

    this my script
    Code:
    try{
                System.out.println("url:" + URL);
                conn = (HttpConnection)Connector.open(URL, Connector.WRITE);
                conn.setRequestMethod(HttpConnection.POST);
    			conn.setRequestProperty("User-Agent", "Profile/MIDP-2.0 Configuration/CLDC-1.1");
                String postData = "";
    
                //InputStream imgIs = getClass().getResourceAsStream(FILE);
    
    //fileconnection
                Enumeration e = FileSystemRegistry.listRoots();
    			String root = (String)e.nextElement();
    			//String filename = "file:///" +root + FILE;
    			String filename ="file:///root/audio.wav";
    			FileConnection fc = (FileConnection)Connector.open(filename, Connector.READ);
    			// FileConnection fc1 = (FileConnection) Connector.open("file:///tmp/audio.wav",Connector.READ);
    			//InputStream imgIs = fc.openInputStream();
    			//InputStream imgIs = (InputStream)fc.openInputStream();
    			//InputStream imgIs = (InputStream)imgIs1.openInputStream();
    			//ByteArrayOutputStream baos = new ByteArrayOutputStream();
    			//writeFileInBaos(baos);
    			//os.write(baos.toByteArray());
    			
    			
    			byte []imgData = new byte[imgIs.available()];
                imgIs.read(imgData);
    
                String message1 = "";
                message1 += "-----------------------------4664151417711" + CrLf;
                message1 += "Content-Disposition: form-data; name=\"uploadedfile\"; filename=\"" + FILE + "\"" + CrLf;
                message1 += "Content-Type: audio/wav" + CrLf;
                message1 += CrLf;
    
                // the image is sent between the messages ni the multipart message.
    
                String message2 = "";
                message2 += CrLf + "-----------------------------4664151417711--" + CrLf;               
    
                conn.setRequestProperty("Content-Type", "multipart/form-data; boundary=---------------------------4664151417711");
                // might not need to specify the content-length when sending chunked data.
                // conn.setRequestProperty("Content-Length", String.valueOf((message1.length() + message2.length() + imgData.length)));
    
                System.out.println("open os");
                os = conn.openOutputStream();
    			//writeFileInBaos(baos);
                System.out.println(message1);
                os.write(message1.getBytes());
    			//os.write(message1.toByteArray());
    
                // SEND THE IMAGE
                int index = 0;
                int size = 10240;
                do{
                    System.out.println("write:" + index);
    				System.out.println("size :" + imgData.length);
                    if((index+size)>imgData.length){
                        size = imgData.length - index; 
                    }
                    os.write(imgData, index, size);
                    index+=size;
                    //progress(imgData.length, index); // update the progress bar.
    
                }while(index<imgData.length);
                System.out.println("written:" + index);            
    
                System.out.println(message2);
                os.write(message2.getBytes());
                os.flush();
    
                System.out.println("open is");
                is = conn.openInputStream();
    
                char buff = 512;
                int len;
                byte []data = new byte[buff];
                do{
                    System.out.println("READ");
                    len = is.read(data);
    
                    if(len > 0){
                        System.out.println(new String(data, 0, len));
                    }
                }while(len>0);
    
                System.out.println("DONE");

  2. #2
    Registered User
    Join Date
    Oct 2009
    Location
    Noida
    Posts
    941

    Re: [ask] upload files from J2ME to PC server?

    Please let us know, where you are stuck... whats not working in this code.

    Try to take help from http://wiki.forum.nokia.com/index.ph...oad_in_Java_ME
    Thanks,
    Ekta

  3. #3
    Registered User
    Join Date
    Jun 2010
    Posts
    2

    Re: [ask] upload files from J2ME to PC server?

    Quote Originally Posted by ektasrv View Post
    Please let us know, where you are stuck... whats not working in this code.

    Try to take help from http://wiki.forum.nokia.com/index.ph...oad_in_Java_ME
    hi ekta thank's for relpy...

    my problem is i cann't upload my file into server. i think the problem is from input stream.

    do ypu have code for my problem?i really need this code....T_T

    thank's
    enda

Similar Threads

  1. how to upload/download file to FTP server in J2ME
    By shahzad73 in forum Mobile Java General
    Replies: 4
    Last Post: 2011-02-24, 09:54
  2. Replies: 0
    Last Post: 2010-02-03, 04:41
  3. upload file image to server using J2ME (Please Help)
    By afuafu in forum Mobile Java General
    Replies: 3
    Last Post: 2007-05-27, 15:43
  4. download/upload xml from-to server in j2me
    By freezenik in forum Mobile Java Networking & Messaging & Security
    Replies: 0
    Last Post: 2005-01-26, 05:00
  5. What phone can DOWNLOAD & UPLOAD to a PC for testing J2ME?
    By toraware in forum Mobile Java General
    Replies: 6
    Last Post: 2004-11-06, 14:42

Posting Permissions

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