# Media upload

The media upload feature lets you store data that you can use in
Display \& Video 360. The kind of data that one might want to upload include photos,
videos, zip files, etc.

## Upload options

The Display \& Video 360 API lets you upload certain types of binary data, or media.
Characteristics of the data you can upload are detailed in the developer guide
for any task that requires a media upload:

- **Maximum upload file size**: The maximum amount of data you can store with this method.
- **Accepted media MIME types**: The types of binary data you can store using this method.

You can make upload requests in any of the following ways. Specify your method
you are using with the `uploadType` parameter.

- [Simple upload](https://developers.google.com/display-video/api/guides/concepts/general/media-upload#simple_upload): `uploadType=media`. A quick transfer for files roughly 5 MB or less.
- [Multipart upload](https://developers.google.com/display-video/api/guides/concepts/general/media-upload#multipart_upload): `uploadType=multipart`. A quick transfer for files and relevant metadata. Transfers the file and metadata, all in a single request.

When you upload media, you use a `/upload` URI. Use this URI when transferring
the media data itself.

Example:

```
  POST /upload/media/resource-name
```

### Simple upload

A simple upload request is the most straightforward method for uploading a file.
This is a good choice when:

- The file is small enough to upload again, if necessary.
- There is no metadata to send. This might be true if metadata is not necessary or is included elsewhere in the request.

To use simple upload, make a `POST` or `PUT` request to the method's `/upload`
URI and add the query parameter `uploadType=media`. For example:

```
  POST https://displayvideo.googleapis.com/upload/media/resource-name?uploadType=media
```

The HTTP headers to use when doing a simple upload include:

- `Content-Type`. Set to one of the method's accepted media data types.
- `Content-Length`. Set to the number of bytes you are uploading. Not required if you are using [chunked transfer encoding](https://datatracker.ietf.org/doc/html/rfc7230#section-4.1).

### Multipart upload

If you have metadata to send with the data to upload, you can make a
`multipart/related` request. This is a good choice if the data you are sending
is small enough to upload again, if necessary.

To use multipart upload, make a `POST` or `PUT` request to the method's
`/upload` URI and add the query parameter `uploadType=multipart`. For example:

```
  POST https://displayvideo.googleapis.com/upload/v4/advertisers/advertiser-id/assets?uploadType=multipart
```

The top-level HTTP headers to use when making a multipart upload request
include:

- `Content-Type`. Set to `multipart/related` and include the boundary string you're using to identify the parts of the request.
- `Content-Length`. Set to the total number of bytes in the request body. The media portion of the request must be less than the maximum file size specified for this method.

The body of the request is formatted as a `multipart/related` content type
\[[RFC2387](https://datatracker.ietf.org/doc/html/rfc2387)\] and contains exactly two parts. The parts are
identified by a boundary string, and the final boundary string is followed by
two hyphens.

Each part of the multipart request needs an additional `Content-Type` header:

1. **Metadata part** : Must come first, and `Content-Type` must match one of the accepted metadata formats.
2. **Media part** : Must come second, and `Content-Type` must match one the method's accepted media MIME types.

## Examples

You upload media using Display \& Video 360 API to do various tasks. This section provides
examples as curl requests.

### Upload creative asset

Here's how to upload a creative asset:

    curl --request POST \
      'https://displayvideo.googleapis.com/upload/v4/advertisers/advertiser-id/assets?uploadType=multipart' \
      --header 'Authorization: Bearer access-token' \
       -F "data={\"filename\": \"asset-filename\"};type=application/json;charset=UTF-8" \
       -F "file=@asset-path;type=asset-mime-type"

See the [Upload creative assets](https://developers.google.com/display-video/api/guides/tasks/assign-creative/upload-assets) guide for more details and
code examples.

### Upload custom bidding script file

Here's how to upload a script file:

    curl --request POST \
      'https://displayvideo.googleapis.com/upload/media/resource-name?uploadType=media' \
      -H 'authorization: Bearer access-token' \
      -H 'Content-Type: text/plain' \
      --data-binary @script-path

See the [Upload script](https://developers.google.com/display-video/api/guides/tasks/implement-custom-bidding/upload-script) guide for more details and code
examples.