Module bus.http

Class MultipartBody

java.lang.Object
org.miaixz.bus.http.bodys.RequestBody
org.miaixz.bus.http.bodys.MultipartBody

public class MultipartBody extends RequestBody
A MIME multipart request body.

This class represents a composite request body of type multipart/related, used for uploading multiple parts (such as files and form data). Each part is separated by a boundary and can have its own custom headers and content type.

Since:
Java 17+
Author:
Kimi Liu
  • Method Details

    • type

      public org.miaixz.bus.core.lang.MediaType type()
      Returns the original media type.
      Returns:
      The original media type.
    • boundary

      public String boundary()
      Returns the boundary separator.
      Returns:
      The boundary string.
    • size

      public int size()
      Returns the number of parts in this multipart body.
      Returns:
      The number of parts.
    • parts

      public List<MultipartBody.Part> parts()
      Returns the list of parts.
      Returns:
      An unmodifiable list of parts.
    • part

      public MultipartBody.Part part(int index)
      Returns the part at the specified index.
      Parameters:
      index - The index.
      Returns:
      The part instance.
    • contentType

      public org.miaixz.bus.core.lang.MediaType contentType()
      Returns the full media type, including the boundary.
      Specified by:
      contentType in class RequestBody
      Returns:
      The media type with the boundary.
    • contentLength

      public long contentLength() throws IOException
      Returns the length of this request body in bytes.
      Overrides:
      contentLength in class RequestBody
      Returns:
      The content length.
      Throws:
      IOException - if the length cannot be determined.
    • writeTo

      public void writeTo(org.miaixz.bus.core.io.sink.BufferSink sink) throws IOException
      Writes the content of this request body to the given sink.
      Specified by:
      writeTo in class RequestBody
      Parameters:
      sink - The sink to write to.
      Throws:
      IOException - if an I/O error occurs.