Class Multipart

All Implemented Interfaces:
Proxy

@Generated("org.javagi.JavaGI") public class Multipart extends ProxyInstance

Represents a multipart HTTP message body, parsed according to the syntax of RFC 2046.

Of particular interest to HTTP are multipart/byte-ranges and multipart/form-data,

Although the headers of a Multipart body part will contain the full headers from that body part, libsoup does not interpret them according to MIME rules. For example, each body part is assumed to have "binary" Content-Transfer-Encoding, even if its headers explicitly state otherwise. In other words, don't try to use Multipart for handling real MIME multiparts.

  • Constructor Details

    • Multipart

      public Multipart(MemorySegment address)
      Create a Multipart proxy instance for the provided memory address.
      Parameters:
      address - the memory address of the native object
    • Multipart

      public Multipart(String mimeType)

      Creates a new empty Multipart with a randomly-generated boundary string.

      Note that mimeType must be the full MIME type, including "multipart/".

      See also: Message.fromMultipart(String, Multipart).

      Parameters:
      mimeType - the MIME type of the multipart to create.
  • Method Details

    • getType

      public static @Nullable Type getType()
      Get the GType of the Multipart class.
      Returns:
      the GType
    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      The memory layout of the native struct.
      Returns:
      the memory layout
    • fromMessage

      public static @Nullable Multipart fromMessage(MessageHeaders headers, byte[] body)
      Parses headers and body to form a new Multipart
      Parameters:
      headers - the headers of the HTTP message to parse
      body - the body of the HTTP message to parse
      Returns:
      a new SoupMultipart (or null if the message couldn't be parsed or wasn't multipart).
    • appendFormFile

      public void appendFormFile(String controlName, @Nullable String filename, @Nullable String contentType, byte[] body)

      Adds a new MIME part containing body to this Multipart

      Uses "Content-Disposition: form-data", as per the HTML forms specification.

      Parameters:
      controlName - the name of the control associated with this file
      filename - the name of the file, or null if not known
      contentType - the MIME type of the file, or null if not known
      body - the file data
    • appendFormString

      public void appendFormString(String controlName, String data)

      Adds a new MIME part containing data to multipart.

      Uses "Content-Disposition: form-data", as per the HTML forms specification.

      Parameters:
      controlName - the name of the control associated with data
      data - the body data
    • appendPart

      public void appendPart(MessageHeaders headers, byte[] body)

      Adds a new MIME part to this Multipart with the given headers and body.

      (The multipart will make its own copies of headers and body, so you should free your copies if you are not using them for anything else.)

      Parameters:
      headers - the MIME part headers
      body - the MIME part body
    • free

      public void free()
      Frees multipart.
    • getLength

      public int getLength()
      Gets the number of body parts in multipart.
      Returns:
      the number of body parts in this Multipart
    • getPart

      public boolean getPart(int part, Out<MessageHeaders> headers, Out<byte[]> body)
      Gets the indicated body part from multipart.
      Parameters:
      part - the part number to get (counting from 0)
      headers - return location for the MIME part headers
      body - return location for the MIME part body
      Returns:
      true on success, false if part is out of range (in which case headers and body won't be set)
    • toMessage

      public void toMessage(MessageHeaders destHeaders, Out<byte[]> destBody)
      Serializes this Multipart to destHeaders and destBody.
      Parameters:
      destHeaders - the headers of the HTTP message to serialize this Multipart to
      destBody - the body of the HTTP message to serialize this Multipart to