## SoupMultipart

SoupMultipart — multipart HTTP message bodies

## Functions

SoupMultipart * | soup_multipart_new ()
SoupMultipart * | soup_multipart_new_from_message ()
void | soup_multipart_free ()
int | soup_multipart_get_length ()
gboolean | soup_multipart_get_part ()
void | soup_multipart_append_part ()
void | soup_multipart_append_form_string ()
void | soup_multipart_append_form_file ()
void | soup_multipart_to_message ()

## Types and Values

| SoupMultipart

## Object Hierarchy

        GBoxed
        ╰── SoupMultipart

## Includes

    #include <libsoup/soup.h>

## Description

Functions to use multi-part HTTP messages.

## Functions

### soup_multipart_new ()

    SoupMultipart *
    soup_multipart_new (const char *mime_type);

Creates a new empty SoupMultipart with a randomly-generated boundary string. Note that `mime_type` must be the full MIME type, including "multipart/".

#### Parameters

mime_type | the MIME type of the multipart to create. |

#### Returns

a new empty SoupMultipart of the given `mime_type`

See also: `soup_message_new_from_multipart()`

### soup_multipart_new_from_message ()

    SoupMultipart *
    soup_multipart_new_from_message (SoupMessageHeaders *headers,
                                     GBytes *body);

Parses `headers` and `body` to form a new SoupMultipart

#### 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).

[nullable]

### soup_multipart_free ()

    void
    soup_multipart_free (SoupMultipart *multipart);

Frees `multipart`

#### Parameters

multipart | a SoupMultipart |

### soup_multipart_get_length ()

    int
    soup_multipart_get_length (SoupMultipart *multipart);

Gets the number of body parts in `multipart`

#### Parameters

multipart | a SoupMultipart |

#### Returns

the number of body parts in `multipart`

### soup_multipart_get_part ()

    gboolean
    soup_multipart_get_part (SoupMultipart *multipart,
                             int part,
                             SoupMessageHeaders **headers,
                             GBytes **body);

Gets the indicated body part from `multipart` .

#### Parameters

multipart | a SoupMultipart |
part | the part number to get (counting from 0) |
headers | return location for the MIME part headers. | [out][transfer none]
body | return location for the MIME part body. | [out][transfer none]

#### Returns

`TRUE` on success, `FALSE` if `part` is out of range (in which case `headers` and `body` won't be set)

### soup_multipart_append_part ()

    void
    soup_multipart_append_part (SoupMultipart *multipart,
                                SoupMessageHeaders *headers,
                                GBytes *body);

Adds a new MIME part to `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

multipart | a SoupMultipart |
headers | the MIME part headers |
body | the MIME part body |

### soup_multipart_append_form_string ()

    void
    soup_multipart_append_form_string (SoupMultipart *multipart,
                                       const char *control_name,
                                       const char *data);

Adds a new MIME part containing `data` to `multipart` , using "Content-Disposition: form-data", as per the HTML forms specification.

#### Parameters

multipart | a multipart (presumably of type "multipart/form-data") |
control_name | the name of the control associated with `data` |
data | the body data |

### soup_multipart_append_form_file ()

    void
    soup_multipart_append_form_file (SoupMultipart *multipart,
                                     const char *control_name,
                                     const char *filename,
                                     const char *content_type,
                                     GBytes *body);

Adds a new MIME part containing `body` to `multipart` , using "Content-Disposition: form-data", as per the HTML forms specification.

#### Parameters

multipart | a multipart (presumably of type "multipart/form-data") |
control_name | the name of the control associated with this file |
filename | the name of the file, or `NULL` if not known |
content_type | the MIME type of the file, or `NULL` if not known |
body | the file data |

### soup_multipart_to_message ()

    void
    soup_multipart_to_message (SoupMultipart *multipart,
                               SoupMessageHeaders *dest_headers,
                               GBytes **dest_body);

Serializes `multipart` to `dest_headers` and `dest_body` .

#### Parameters

multipart | a SoupMultipart |
dest_headers | the headers of the HTTP message to serialize `multipart` to |
dest_body | the body of the HTTP message to serialize `multipart` to. | [out]

## Types and Values

### SoupMultipart

    typedef struct _SoupMultipart SoupMultipart;

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 SoupMultipart 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 SoupMultipart for handling real MIME multiparts.

## See Also

SoupMessageBody, SoupMessageHeaders