As I said, multipart uploads aren't hard to do your own function for.

    private void UploadFile(String FileName)
    {
    try
    {
        String lineEnd = "\r\n";
        String twoHyphens = "--";
        String boundary =  "*****MyMultiPartBoundary";

        File sdcard = Environment.getExternalStorageDirectory();
        File mydir = new File(sdcard, "MyFileDir");
        File file = new File(mydir, FileName);

        FileInputStream fileInputStream = new FileInputStream(file);

        String UPLOADSCRIPT_URL = "
http://www.example.com/upload.php?username=example&password=example";;
        System.out.println("Opening: "+UPLOADSCRIPT_URL);
        URL url = new URL(UPLOADSCRIPT_URL);
        HttpURLConnection conn = (HttpURLConnection)url.openConnection();

        conn.setDoInput(true);
        conn.setDoOutput(true);
        conn.setUseCaches(false);

                conn.setRequestMethod("POST");
                conn.setRequestProperty("User-Agent",
"MyExampleApp/"+appversion);
                conn.setRequestProperty("Content-Type",
"multipart/form-data;boundary="+boundary);
                conn.connect();
                DataOutputStream dos = new
DataOutputStream(conn.getOutputStream());
                dos.writeBytes(twoHyphens + boundary + lineEnd);
                dos.writeBytes("Content-Disposition: form-data;
name=\"uploadedfile\";filename=\""+
                                    FileName+"\"" + lineEnd);
                dos.writeBytes(lineEnd);

                int bytesAvailable;

                while((bytesAvailable = fileInputStream.available()) > 0)
                {
                    int bufferSize = Math.min(bytesAvailable, 4096);
                    byte[] buffer = new byte[bufferSize];
                    int bytesRead = fileInputStream.read(buffer, 0,
bufferSize);
                    dos.write(buffer, 0, bytesRead);
                }

                dos.writeBytes(twoHyphens + boundary + twoHyphens +
lineEnd);
                fileInputStream.close();
                dos.flush();
                dos.close();
                DataInputStream dis = new
DataInputStream(conn.getInputStream());
                byte[] data = new byte[1024];
                len = dis.read(data, 0, 1024);
                dis.close();
                int respcode = conn.getResponseCode();
                System.out.println("done uploading! resp code = "+respcode);
                String respstr = "FAILED";
                if(len > 0)
                    respstr = new String(data, 0, len);

                if(respcode == 200 && respstr.equals("OK"))
            System.out.println("Uploaded "+FileName+" successfully!");
        else
            System.out.println("Upload Error: respcode="+respcode+",
respstr="+respstr);
    } catch (Exception e) {
        System.out.println("upload error: "+e.toString());
    }
}

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to