<!-- https://api-docs.fansmetric.com/uploading-media -->
# Uploading Media

Section: Getting Started › Getting started. Page: https://api-docs.fansmetric.com/uploading-media

Send a new photo or video: upload it, register it with OnlyFans, then attach it to a message. Every step goes through this API except sending the file itself, which goes straight to the upload address you are given.

## The steps

One file takes up to six calls. Only step 3 skips this API: the file goes straight to the addresses from step 2, with no API key.

For several files, run the steps once per file. Different files can go at the same time.

One permission, `api_media_upload`, covers every step that goes through this API.

- 1. Optional: check whether the vault already has the file — [Lookup Vault Media by Hash](https://api-docs.fansmetric.com/api-reference/vault/lookup-hash)
- 2. Get the addresses to upload to — [Create Signed Upload](https://api-docs.fansmetric.com/api-reference/media-upload/create-signed-upload)
- 3. Send the file to those addresses — directly
- 4. Files over 5 MB only: join the pieces — [Finish Multipart Upload](https://api-docs.fansmetric.com/api-reference/media-upload/finish-multipart-upload)
- 5. Register the file — [Convert Upload](https://api-docs.fansmetric.com/api-reference/media-upload/convert-upload)
- 6. Attach it to a message — [Send Message](https://api-docs.fansmetric.com/api-reference/messages/send-message) or [Send Mass Message](https://api-docs.fansmetric.com/api-reference/mass-messages/send)

## One piece or several

Files of 5 MB (5,242,880 bytes) or less go up in one piece. Bigger files go up in pieces of exactly 5,242,880 bytes, with whatever is left over in the last piece — the same split the OnlyFans website uses.

## 1. Skip files the vault already has

[Lookup Vault Media by Hash](https://api-docs.fansmetric.com/api-reference/vault/lookup-hash) takes the file's fingerprint as `h` and its size in bytes as `size`. If the vault already has the file, you get the vault item back: put its `id` in `mediaFiles` and skip the remaining steps. A `404` means it isn't there, so carry on.

The fingerprint is an MD5 hash, worked out the way the file will go up:

- Files of 5 MB or less: the MD5 of the whole file, as 32 lowercase letters and digits
- Bigger files: take the MD5 of each 5 MB piece, join those hashes together as raw bytes (16 per piece, not the 32-character text), take the MD5 of that, and add `-` and the number of pieces, such as `…-3`. It equals the `ETag` that [Finish Multipart Upload](https://api-docs.fansmetric.com/api-reference/media-upload/finish-multipart-upload) gives the joined file, without its quotes.

## 2–4. Upload the file

[Create Signed Upload](https://api-docs.fansmetric.com/api-reference/media-upload/create-signed-upload) takes the file's name, its size in bytes and its type, and answers with where to send the file. Send it there with a `PUT`, setting `Content-Type` and `Content-Length`.

Keep `key` and `uploadToken` from that answer, and the `putUrl` you sent the file to. Registering the file needs all three.

- One piece: send the whole file to `putUrl`, and keep the `ETag` header it answers with
- Several pieces: send piece 1 to the first `putUrl` in `keys[]`, piece 2 to the second, and so on. They can go at the same time. Keep the `ETag` header each piece answers with.
- Then join the pieces with [Finish Multipart Upload](https://api-docs.fansmetric.com/api-reference/media-upload/finish-multipart-upload), using the `key` from the answer. It answers with the joined file's `ETag`.

## 5. Register the file

OnlyFans can't use the file until it's registered. Send [Convert Upload](https://api-docs.fansmetric.com/api-reference/media-upload/convert-upload) what the earlier steps gave you. It applies the account's upload settings and watermark for you, and answers with the file ready to attach.

- `key` and `uploadToken` — from the Create Signed Upload answer
- `putUrl` — the address you sent the file to. For pieces, the first piece's.
- `ETag` — one piece: the `ETag` header from sending the file, which is also the file's MD5. Pieces: the `ETag` from Finish Multipart Upload.
- `contentType` — the file type you gave Create Signed Upload

## 6. Attach it to a message

Put the `data` from Convert Upload — `{ "processId": …, "host": …, "name": …, "extra": … }` — in `mediaFiles` of [Send Message](https://api-docs.fansmetric.com/api-reference/messages/send-message) or [Send Mass Message](https://api-docs.fansmetric.com/api-reference/mass-messages/send), as it is.

Vault IDs and new uploads can share one `mediaFiles` list. For `previews` on a paid message, use vault IDs.

Sending the message is also what puts the file in the vault — registering alone doesn't.

## Keep it in the vault and tag creators

A registered file isn't in the vault yet: it gets there when it's sent in a message.

To store files in the vault without leaving them in a chat, do what the FansMetric app does: send them to a fan in a free message with no text, take the vault IDs from `media[].id` in the answer, then remove the message with [Unsend Message](https://api-docs.fansmetric.com/api-reference/messages/delete-message). The files stay in the vault. The message does reach the fan until it's unsent, so choose the fan with care.

To tag the creators who appear in a file, send their OnlyFans user IDs and the file's vault ID to [Attach Tags To Vault Media](https://api-docs.fansmetric.com/api-reference/vault/attach-tags). A file that was only just sent can take a few seconds to reach the vault: the app waits 3 seconds and tries up to 3 times.

## If something fails

The answer says what went wrong. The ones you are most likely to see:

- `400` from any step — a field is missing or the wrong type, and the message names it
- `400` with `Invalid input.` from Convert Upload — `key` or `uploadToken` doesn't match the upload. Use the `key` from the Create Signed Upload answer.
- `404` from Lookup Vault Media by Hash — the vault doesn't have the file, so upload it
