# Generates batches of presigned URLs for multipart parts

`POST /uploads/batch-presign-multipart-parts.json`

Multipart uploads are uploaded in chunks or parts to individual presigned
URLs, similar to the one generated by /generate-presigned-put. The part
numbers provided must be between 1 and 10000. The total number of parts
will depend on the chunk size in bytes that you intend to use to upload
each chunk. For example a 12MB file may have 2 5MB chunks and a final
2MB chunk, for part numbers 1, 2, and 3.

This endpoint will return a presigned URL for each part number provided,
which you can then use to send PUT requests for the binary chunk corresponding
to that part. When the part is uploaded, the provider should return an
ETag for the part, and this should be stored along with the part number,
because this is needed to complete the multipart upload.

You must have the correct permissions and CORS settings configured in your
external provider. We support AWS S3 as the default. See:

https://meta.discourse.org/t/-/210469#s3-multipart-direct-uploads-4.

An external file store must be set up and `enable_direct_s3_uploads` must
be set to true for this endpoint to function.



Authentication: no security requirement declared for this operation.

Request body: application/json

Type: any

- `part_numbers` (required)
  Type: array
  
  The part numbers to generate the presigned URLs for,
  must be between 1 and 10000.
  
  Example:
  
  ```json
  [
    1,
    2,
    3
  ]
  ```

- `unique_identifier` (required)
  Type: string
  
  The unique identifier returned in the original /create-multipart
  request.
  
  Example:
  
  ```json
  "66e86218-80d9-4bda-b4d5-2b6def968705"
  ```

Additional properties: false

Responses:

- 200: external upload initialized

Content type: application/json

Type: any

- `presigned_urls` (required)
  Type: object
  
  The presigned URLs for each part number, which has
  the part numbers as keys.
  
  Example:
  
  ```json
  {
    "1": "https://discourse-martin-uploads-test.s3.us-east-2.amazonaws.com/temp/uploads/default/123abc/123abc.jpg?partNumber=1&uploadId=123456abcd&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=test&X-Amz-Date=20211222T012336Z&X-Amz-Expires=600&X-Amz-SignedHeaders=host&X-Amz-Signature=abc123"
  }
  ```

Additional properties: false

## Examples

### cURL

```bash
curl -X POST 'https://discourse.example.com/uploads/batch-presign-multipart-parts.json' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "part_numbers": [
    1,
    2,
    3
  ],
  "unique_identifier": "66e86218-80d9-4bda-b4d5-2b6def968705"
}'
```

### JavaScript

```javascript
const body = `{
  "part_numbers": [
    1,
    2,
    3
  ],
  "unique_identifier": "66e86218-80d9-4bda-b4d5-2b6def968705"
}`;

const response = await fetch('https://discourse.example.com/uploads/batch-presign-multipart-parts.json', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
  },
  body,
});

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

### Python

```python
import requests

body = '''{
  "part_numbers": [
    1,
    2,
    3
  ],
  "unique_identifier": "66e86218-80d9-4bda-b4d5-2b6def968705"
}'''

response = requests.post(
    'https://discourse.example.com/uploads/batch-presign-multipart-parts.json',
    data=body.encode('utf-8'),
    headers={
        'Content-Type': 'application/json',
    },
)
print(response.text)
```
