public void addFilePart(String fieldName, File uploadFile, String fileName) throws IOException {
        if (TextUtils.isEmpty(fileName)) {
            fileName = uploadFile.getName();
        }
        mWriter.append("--" + mBoundary).append(LINE_FEED);
        mWriter.append(
                "Content-Disposition: form-data; name=\"" + fieldName
                        + "\"; filename=\"" + fileName + "\"")
                .append(LINE_FEED);
        mWriter.append(
                "Content-Type: " + URLConnection.guessContentTypeFromName(fileName))
                .append(LINE_FEED);
        mWriter.append("Content-Transfer-Encoding: binary").append(LINE_FEED);
        mWriter.append(LINE_FEED);
        mWriter.flush();

        FileInputStream inputStream = new FileInputStream(uploadFile);
        byte[] buffer = new byte[4096];
        int bytesRead = -1;
        while ((bytesRead = inputStream.read(buffer)) != -1) {
            mOutputStream.write(buffer, 0, bytesRead);
        }
        mOutputStream.flush();
        inputStream.close();

        mWriter.append(LINE_FEED);
        mWriter.flush();
    }
public void addFilePart(String fieldName, File uploadFile, String fileName) throws IOException {
        if (TextUtils.isEmpty(fileName)) {
            fileName = uploadFile.getName();
        }
        mWriter.append("--" + mBoundary).append(LINE_FEED);
        mWriter.append(
                "Content-Disposition: form-data; name=\"" + fieldName
                        + "\"; filename=\"" + fileName + "\"")
                .append(LINE_FEED);
        mWriter.append(
                "Content-Type: " + URLConnection.guessContentTypeFromName(fileName))
                .append(LINE_FEED);
        mWriter.append("Content-Transfer-Encoding: binary").append(LINE_FEED);
        mWriter.append(LINE_FEED);
        mWriter.flush();

        FileInputStream inputStream = new FileInputStream(uploadFile);
        byte[] buffer = new byte[4096];
        int bytesRead = -1;
        while ((bytesRead = inputStream.read(buffer)) != -1) {
            mOutputStream.write(buffer, 0, bytesRead);
        }
        mOutputStream.flush();
        inputStream.close();

        mWriter.append(LINE_FEED);
        mWriter.flush();
    }
public void addFilePart ( String fieldName , File uploadFile , String fileName ) throws IOException { if ( TextUtils . isEmpty ( fileName ) ) { fileName = uploadFile . getName ( ) ; } mWriter . append ( "--" + mBoundary ) . append ( LINE_FEED ) ; mWriter . append ( "Content-Disposition: form-data; name=\"" + fieldName + "\"; filename=\"" + fileName + "\"" ) . append ( LINE_FEED ) ; mWriter . append ( "Content-Type: " + URLConnection . guessContentTypeFromName ( fileName ) ) . append ( LINE_FEED ) ; mWriter . append ( "Content-Transfer-Encoding: binary" ) . append ( LINE_FEED ) ; mWriter . append ( LINE_FEED ) ; mWriter . flush ( ) ; FileInputStream inputStream = new FileInputStream ( uploadFile ) ; byte [ ] buffer = new byte [ 4096 ] ; int bytesRead = - 1 ; while ( ( bytesRead = inputStream . read ( buffer ) ) != - 1 ) { mOutputStream . write ( buffer , 0 , bytesRead ) ; } mOutputStream . flush ( ) ; inputStream . close ( ) ; mWriter . append ( LINE_FEED ) ; mWriter . flush ( ) ; }
Adds a upload file section to the request

@param fieldName  name attribute in <input type="file" name="..." />
@param uploadFile a File to be uploaded
@param fileName   the filename field
@throws IOException
Adds a upload file section to the request