Hi! I am trying the sample code found here. The HttpMultipartRequest class is the same, while the MIDlet being used for testing is as follows:
Code:
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.io.*;
import java.io.*;
import java.util.Hashtable;
import javax.microedition.io.file.FileConnection;

public class PostFile extends MIDlet implements Runnable, CommandListener{
           
    private Form form = null;
    private Gauge gauge = null;
    private Command exitCommand;
    private Command uploadCommand;
    
    public PostFile(){
        form = new Form("Upload File");
        gauge = new Gauge("Progress:", true, 100, 0);
        form.append(gauge);
        
        exitCommand = new Command("Exit", Command.EXIT, 0);
        uploadCommand = new Command("Upload", Command.SCREEN, 0);
        form.addCommand(exitCommand);
        form.addCommand(uploadCommand);
        
        form.setCommandListener(this);
    }
    
    public void startApp() {
        Display.getDisplay(this).setCurrent(form);
    }
    
    public void pauseApp() {
    }
    
    public void destroyApp(boolean unconditional) {
    }
    
    private void progress(int total, int current){
        int percent = (int) (100 * ((float)current/(float)total));
        gauge.setValue(percent);
    }
    
    public void run() {
        try {
            send();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }    
    
    private void send() throws Exception {
        
        byte[] fileBytes = getByteArray(Image.createImage("/image.png")); //retrieve file bytes with your own code
			
        Hashtable params = new Hashtable();
        params.put("custom_param", "param_value");
        params.put("custom_param2", "param_value2");

        HttpMultipartRequest req = new HttpMultipartRequest(
                "http://localhost:80/uploadScript.php",
                params,
                "upload_field", "image.png", "image/png", fileBytes
        );

        byte[] response = req.send();
    }
     
    
    public void commandAction(javax.microedition.lcdui.Command command, javax.microedition.lcdui.Displayable displayable) {
        if(command == exitCommand){
            this.notifyDestroyed();
        }else if(command == uploadCommand){
            new Thread(this).start();
        }
    }
    
    public byte[] getByteArray(Image image) {
        int raw[] = new int[image.getWidth() * image.getHeight()];
        image.getRGB(raw, 0, image.getWidth(), 0, 0, image.getWidth(), image.getHeight());
        byte rawByte[] = new byte[image.getWidth() * image.getHeight() * 4];
        int n = 0;
        for (int i = 0; i < raw.length; i++) {
            int ARGB = raw[i];
            int a = (ARGB & 0xff000000) >> 24;
            int r = (ARGB & 0xff0000) >> 16;
            int g = (ARGB & 0xff00) >> 8;
            int b = ARGB & 0xff;
            rawByte[n] = (byte) b;
            rawByte[n + 1] = (byte) g;
            rawByte[n + 2] = (byte) r;
            rawByte[n + 3] = (byte) a;
            n += 4;
        }
        System.out.println("raw(int) length is: " + raw.length);
        System.out.println("raw(Byte) length is: " + rawByte.length);
        raw = null;
        return rawByte;
    }
}
The PHP file is as follows:
Code:
<?php
 
$filesize = filesize($_FILES['upload_field']['tmp_name']);
 
echo "The uploaded file size is " . $filesize . " bytes\n";
 
foreach($_POST as $key => $value)
{
	echo "Parameter name: " . $key . ", value: " . $value . "\n";
}
 
?>
When I try to run it, I get the following:
Code:
raw(int) length is: 65536
raw(Byte) length is: 262144
java.io.IOException: error 0 during TCP write 
        at com.sun.midp.io.j2me.socket.Protocol.writeBytes(Protocol.java:360)
        at com.sun.midp.io.BaseOutputStream.write(ConnectionBaseAdapter.java:830)
        at java.io.DataOutputStream.write(DataOutputStream.java:90)
        at com.sun.midp.io.j2me.http.Protocol.sendRequestBody(Protocol.java:1896)
        at com.sun.midp.io.j2me.http.Protocol.sendRequest(Protocol.java:1562)
        at com.sun.midp.io.j2me.http.Protocol.writeBytes(Protocol.java:1032)
        at com.sun.midp.io.BaseOutputStream.write(ConnectionBaseAdapter.java:830)
        at java.io.OutputStream.write(OutputStream.java:58)
        at HttpMultipartRequest.send(HttpMultipartRequest.java:109)
        at PostFile.send(PostFile.java:91)
        at PostFile.run(PostFile.java:71)
The file I am using can be downloaded here.

Hope you can help me.
Thanks.