# Upload a video

`POST /api/v1/videos/upload`

Uses a single request to upload a video.

Authentication (security requirement alternatives):

```json
[
  {
    "OAuth2": []
  }
]
```

- OAuth2: oauth2. Authenticating via OAuth requires the following steps:
- Have an activated account
- [Generate] an access token for that account at `/api/v1/users/token`.
- Make requests with the *Authorization: Bearer <token\>* header
- Profit, depending on the role assigned to the account

Note that the __access token is valid for 1 day__ and is given
along with a __refresh token valid for 2 weeks__.

[Generate]: https://docs.joinpeertube.org/api/rest-getting-started


Request body: multipart/form-data

Type: VideoUploadRequestCommon & object

Schema: [VideoUploadRequestLegacy](https://sourcey-peertube.pages.dev/api-rest-reference/models/videouploadrequestlegacy.md)

allOf:
  Reference: [VideoUploadRequestCommon](https://sourcey-peertube.pages.dev/api-rest-reference/models/videouploadrequestcommon.md); Type: VideoUploadRequestCommon

  Type: object
  
  - `videofile` (required)
    Type: string, binary
    
    Video file

Responses:

- 200: successful operation

Content type: application/json

Type: VideoUploadResponse

Schema: [VideoUploadResponse](https://sourcey-peertube.pages.dev/api-rest-reference/models/videouploadresponse.md)

- `video` (optional)
  Type: object
  
  - `id` (optional)
    Reference: [id](https://sourcey-peertube.pages.dev/api-rest-reference/models/id.md); Type: id
    
    object id for the video
  
  - `uuid` (optional)
    Type: UUIDv4
    
    universal identifier for the video, that can be used across instances
    
    allOf:
      Reference: [UUIDv4](https://sourcey-peertube.pages.dev/api-rest-reference/models/uuidv4.md); Type: UUIDv4, uuid
      
      minLength: 36
      
      maxLength: 36
      
      pattern: "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$"
      
      Example:
      
      ```json
      "9c9de5e8-0a1e-484a-b099-e80766180a6d"
      ```
  
  - `shortUUID` (optional)
    Reference: [shortUUID](https://sourcey-peertube.pages.dev/api-rest-reference/models/shortuuid.md); Type: shortUUID

- 403: video didn't pass upload filter

- 408: upload has timed out

- 413: If the response has no body, it means the reverse-proxy didn't let it through. Otherwise disambiguate via `code`:
- `quota_reached` for quota limits whether daily or global


- 415: video type unsupported

- 422: video unreadable

## Examples

### Shell

```Shell
## DEPENDENCIES: jq
USERNAME="<your_username>"
PASSWORD="<your_password>"
FILE_PATH="<your_file_path>"
CHANNEL_ID="<your_channel_id>"
NAME="<video_name>"
API="https://peertube2.cpy.re/api/v1"

## AUTH
client_id=$(curl -s "$API/oauth-clients/local" | jq -r ".client_id")
client_secret=$(curl -s "$API/oauth-clients/local" | jq -r ".client_secret")
token=$(curl -s "$API/users/token" \
  --data client_id="$client_id" \
  --data client_secret="$client_secret" \
  --data grant_type=password \
  --data username="$USERNAME" \
  --data password="$PASSWORD" \
  | jq -r ".access_token")

## VIDEO UPLOAD
curl -s "$API/videos/upload" \
  -H "Authorization: Bearer $token" \
  --max-time 600 \
  --form videofile=@"$FILE_PATH" \
  --form channelId=$CHANNEL_ID \
  --form name="$NAME"
```
