# Send chunk for the resumable replacement of a video

`PUT /api/v1/videos/{id}/source/replace-resumable`

**PeerTube >= 6.0** Uses [a resumable protocol](https://github.com/kukhariev/node-uploadx/blob/master/proto.md) to continue, pause or resume the replacement of 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


Parameters:

- `id` (path, id | UUIDv4 | shortUUID, required) - The object id, uuid or short uuid
  Type: id | UUIDv4 | shortUUID
  
  oneOf:
    Reference: [id](https://sourcey-peertube.pages.dev/api-rest-reference/models/id.md); Type: id
    
    minimum: 1
    
    Example:
    
    ```json
    42
    ```
  
    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"
    ```
  
    Reference: [shortUUID](https://sourcey-peertube.pages.dev/api-rest-reference/models/shortuuid.md); Type: shortUUID
    
    translation of a uuid v4 with a bigger alphabet to have a shorter uuid
    
    Example:
    
    ```json
    "2y84q2MQUMWPbiEcxNXMgC"
    ```

- `upload_id` (query, string, required) - Created session id to proceed with. If you didn't send chunks in the last hour, it is
not valid anymore and you need to initialize a new upload.

  Type: string

- `Content-Range` (header, string, required) - Specifies the bytes in the file that the request is uploading.

For example, a value of `bytes 0-262143/1000000` shows that the request is sending the first
262144 bytes (256 x 1024) in a 2,469,036 byte file.

When the server config `client.videos.resumableUpload.minChunkSize` (video uploads) or
`import.users.resumableUpload.minChunkSize` (user archive imports) is not `0`,
every chunk except the last one must be at least that big. It must also be at least 1/10,000 of the file size
(the maximum number of object storage multipart upload parts).

  Type: string
  
  Example:
  
  ```json
  "bytes 0-262143/2469036"
  ```

- `Content-Length` (header, number, required) - Size of the chunk that the request is sending.

Remember that larger chunks are more efficient. PeerTube's web client uses chunks varying from
1048576 bytes (~1MB) and increases or reduces size depending on connection health.

  Type: number
  
  Example:
  
  ```json
  262144
  ```

Request body: application/octet-stream

Type: string, binary

Responses:

- 204: last chunk received: successful operation

- 308: resume incomplete

- 400: chunk is smaller than `client.videos.resumableUpload.minChunkSize` of the server config or 1/10,000 of the file size (and is not the last one)

- 403: video didn't pass file replacement filter

- 404: replace upload not found

- 409: chunk doesn't match range

- 422: video unreadable

- 429: too many concurrent requests

- 503: upload is already being processed

## Examples

### cURL

```bash
curl -X PUT 'https://peertube2.cpy.re/api/v1/videos/42/source/replace-resumable?upload_id=string' \
  -H 'Content-Range: bytes 0-262143/2469036' \
  -H 'Content-Length: 262144' \
  -H 'Authorization: Bearer YOUR_TOKEN'
```

### JavaScript

```javascript
const response = await fetch('https://peertube2.cpy.re/api/v1/videos/42/source/replace-resumable?upload_id=string', {
  method: 'PUT',
  headers: {
    'Content-Range': 'bytes 0-262143/2469036',
    'Content-Length': '262144',
    'Authorization': 'Bearer YOUR_TOKEN',
  },
});

const data = await response.text();
```

### Python

```python
import requests

response = requests.put(
    'https://peertube2.cpy.re/api/v1/videos/42/source/replace-resumable?upload_id=string',
    headers={
        'Content-Range': 'bytes 0-262143/2469036',
        'Content-Length': '262144',
        'Authorization': 'Bearer YOUR_TOKEN',
    },
)
print(response.text)
```
