# Generate Upload Presigned Url

## Purpose

Generate signed urls for S3, allowing short lived access to upload files without providing public access. Ensuring the file is renamed to the specified GUID to prevent conflicts.

## Inputs

```json
{
    "region":"eu-west-1",
    "bucket":"remind-ugc",
    "key":"1sdf-63ks-i3ol-adjk"
}
```

### Region

Must be a valid AWS region. No validation is performed on content, only presence.

### Bucket

Must be a valid bucket within the specified region. No validation is performed on content, only presence.

### Key

Must be a valid aws key. Leading slashes can break signatures. ie. Prefer `path/to/file` to `/path/to/file`.

General consensus is to use GUIDs to identify objects. 

> If you request upload to an **existing** GUID it will be **REPLACED**.

## Side Effects

None

## Responses

### 422 BAD REQUEST

Content failed validation. Errors will be attached.

### 200 OK

Data contains:

```json
{
    "url": "http://bucket.s3.signed.content.com/whatever/key/you/selected/with?a&stack&of&query&params&and&header&info&signatures"
}
```
This being successful **DOES NOT** imply the Url will work, only that the given presigned data was valid at the time of creation. If you put the wrong headers on the request you will have signature errors. This includes things like: trying to GET a presigned url for PUT.

#### 200 OK Example

```json
{
  "isBase64Encoded": false,
  "statusCode": 200,
  "headers": {
    "Access-Control-Allow-Origin": "*",
    "Access-Control-Allow-Credentials": true
  },
  "body": "{\"success\":true,\"message\":\"Generated\",\"data\":{\"url\":\"https://remind-ugc.s3.eu-west-1.amazonaws.com/1qw6-elra-k9op-k2q2?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=ASIAUDGT45ROWLDELOXC%2F20210907%2Feu-west-1%2Fs3%2Faws4_request&X-Amz-Date=20210907T092140Z&X-Amz-Expires=900&X-Amz-Security-Token=IQoJb3JpZ2luX2VjEEIaCWV1LXdlc3QtMSJHMEUCIQD5gMVK1wv%2FNKC3SSUPb7GpFly%2Flmcf9%2BEWBpscWdmrMAIgPuOQ%2FFGDGA5p0eZh4SqoUVgnkwJx10OnCmDzcDKyf8IqtQIIiv%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FARAAGgwyODE3NjQ3NTI0NzciDK8uQJx2EciTTqmA1iqJAgBGPEGZVCJDOJ0wzbCTc3r7dtSAFagAnDbIBudF97oVK6pRUA6sK7fhdPBn65yfrPCurZC14nEpzTeLc%2Fai6di17b7TqdPlTrP7JH7QOp04DEAL6zJeagSGR1UZvWSc6PV76pVj9m6S1YkUZCTueWsayYUK2Z%2F35wPVZiI4mZuRq35K8sFTuFg%2BEchQqOEsbjjYgf8n8EgDF20XXo%2F%2B7LNg0jjNDFJYEbvv%2FCdfMxB4UZ1CN00YCPbLcmatLIzrNGoUI8JIuN%2BHiYyA4wRKZ%2FE7iknTNkyb7Uz1D0vcxCVbw0N%2FalcGgWCdjc6K6ACyBde5JYYVIasJiwIMdHr3KBVs2OIZr8mZNBIwpN7ciQY6mgGkTWP9EXjmkGORyptQYr21iwqR2znA7DU4ZeuT4KQHtEyD6joPBSJpXm4iMi4AQtW3ZV6TdXTTjIG0piRk6ikDQcq03WOCZfzbkVgAPh7TPlQ%2BFaub8Zhc2ml0kUidMQe70YO4nHcw5Y4fvxR5XnV1W6i7FybCnu4cuzsY%2FPlDQJZJI9A1sFEK5x%2BAmq60L7aiSCcJ%2F27YCV%2BX&X-Amz-Signature=c1dd7a1d5402610708adf80ddd21e74069f79a2f47f51850eee3e75b19baf60b&X-Amz-SignedHeaders=host\"},\"errors\":null}"
}
```

### 500 SERVER ERROR

This and its ascociated error information indicates there was an error within S3 Client, and it is reported directly to the caller as errors via the format specified in `getRepsonseFormat`.