Class MultipartBody.Builder

java.lang.Object
dev.ua.theroer.magicutils.http.MultipartBody.Builder
Enclosing class:
MultipartBody

public static final class MultipartBody.Builder extends Object
Builder for multipart/form-data content.
  • Constructor Details

    • Builder

      public Builder()
      Creates a new builder.
  • Method Details

    • boundary

      public MultipartBody.Builder boundary(String boundary)
      Overrides the multipart boundary string.
      Parameters:
      boundary - boundary value
      Returns:
      this builder
    • text

      public MultipartBody.Builder text(String name, String value)
      Adds a text field part.
      Parameters:
      name - field name
      value - field value
      Returns:
      this builder
    • file

      public MultipartBody.Builder file(String name, Path path) throws IOException
      Adds a file part with a detected content type.
      Parameters:
      name - field name
      path - file path
      Returns:
      this builder
      Throws:
      IOException - if the file cannot be read
    • file

      public MultipartBody.Builder file(String name, Path path, String contentType, String filename) throws IOException
      Adds a file part with custom content type and filename.
      Parameters:
      name - field name
      path - file path
      contentType - content type or null to auto-detect
      filename - file name or null to use the path name
      Returns:
      this builder
      Throws:
      IOException - if the file cannot be read
    • bytes

      public MultipartBody.Builder bytes(String name, byte[] data, String contentType, String filename)
      Adds a raw byte part with optional content type and filename.
      Parameters:
      name - field name
      data - byte array payload
      contentType - content type or null for default
      filename - filename or null for default
      Returns:
      this builder
    • build

      public MultipartBody build()
      Builds the multipart body.
      Returns:
      multipart body