public RequestBody buildRequestBodyMultipart(Map<String, Object> formParams) {
        MultipartBuilder mpBuilder = new MultipartBuilder().type(MultipartBuilder.FORM);
        for (Entry<String, Object> param : formParams.entrySet()) {
            if (param.getValue() instanceof File) {
                File file = (File) param.getValue();
                Headers partHeaders = Headers.of("Content-Disposition", "form-data; name=\"" + param.getKey() + "\"; filename=\"" + file.getName() + "\"");
                MediaType mediaType = MediaType.parse(guessContentTypeFromFile(file));
                mpBuilder.addPart(partHeaders, RequestBody.create(mediaType, file));
            } else {
                Headers partHeaders = Headers.of("Content-Disposition", "form-data; name=\"" + param.getKey() + "\"");
                mpBuilder.addPart(partHeaders, RequestBody.create(null, parameterToString(param.getValue())));
            }
        }
        return mpBuilder.build();
    }
public RequestBody buildRequestBodyMultipart ( Map < String , Object > formParams ) { MultipartBuilder mpBuilder = new MultipartBuilder ( ) . type ( MultipartBuilder . FORM ) ; for ( Entry < String , Object > param : formParams . entrySet ( ) ) { if ( param . getValue ( ) instanceof File ) { File file = ( File ) param . getValue ( ) ; Headers partHeaders = Headers . of ( "Content-Disposition" , "form-data; name=\"" + param . getKey ( ) + "\"; filename=\"" + file . getName ( ) + "\"" ) ; MediaType mediaType = MediaType . parse ( guessContentTypeFromFile ( file ) ) ; mpBuilder . addPart ( partHeaders , RequestBody . create ( mediaType , file ) ) ; } else { Headers partHeaders = Headers . of ( "Content-Disposition" , "form-data; name=\"" + param . getKey ( ) + "\"" ) ; mpBuilder . addPart ( partHeaders , RequestBody . create ( null , parameterToString ( param . getValue ( ) ) ) ) ; } } return mpBuilder . build ( ) ; }
Build a multipart (file uploading) request body with the given form parameters,
which could contain text fields and file fields.

@param formParams Form parameters in the form of Map
@return RequestBody