Trouble with method network.upload... HELP PLEASE!

how can i upload an image to a server?

 

I have a trouble with the method network.upload is that, when i need upload an image to a java server but this method puts a headers that corrupt the file and i cant work with the file, because I need the server to process the image, but is not received correctly. I work in java with sockets. Here is the example…

 

Lua client

 

local function networkListener( event )

         if ( event.isError ) then

                 print( “Network error!”)

         elseif ( event.phase == “ended” ) then

                print ( “Upload complete!” )

         end

 end

 

network.upload( 

         “http://localhost:9000”, 

          “POST”, 

         networkListener, 

         “test.jpg”, 

         system.DocumentsDirectory, 

         “image/jpg” 

        )

 

java server

 

public class Server implements Runnable {

    ServerSocket server;

    public Server() {

        try {

            server=new ServerSocket(9000);

            System.out.println(“Server running…”);

        } catch(Exception e) {

            System.out.println(“Error !\n”+e);

            System.exit(1);

        }

    }

 

    public void run() {

        Socket client=null;

        while (true) {

            if (server==null)

                return;

            try {

                client=server.accept();

                System.out.println(“get a client !”);

            } catch(java.io.IOException e) {

                System.err.println(“conection failed” + e.getMessage());

            }

            try {

                java.io.InputStream in = client.getInputStream();

                java.io.FileOutputStream out = new java.io.FileOutputStream(new java.io.File(“D:\test.jpg”));

                byte[] buf = new byte[1024];

                int len;

                while ((len = in.read(buf)) > 0) {

                    out.write(buf, 0, len);

                }

                in.close();

                out.close();

                server.close();

            } catch(java.io.IOException e) {

                System.out.println("Error: " + e);

            }

        }

    }

 

    public static void main(String a[]) {

        Server server = new Server();

        new Thread(server).start();

    }

}

 

 

original image file before sending

thump_8740595captura1.png

 

image file after sending

thump_8740594captura.png

 

How can i do to delete these headers?

 

Thanks a lot!