2019-03-31 18:10:32 +00:00
|
|
|
Guide - Setup CodiMD S3 image upload
|
|
|
|
===
|
2018-06-24 12:04:35 +00:00
|
|
|
|
2019-03-31 18:10:32 +00:00
|
|
|
**Note:** *This guide was written before the renaming. Just replace `HackMD` with `CodiMD` in your mind :smile: thanks!*
|
2016-11-16 06:27:18 +00:00
|
|
|
|
|
|
|
1. Go to [AWS S3 console](https://console.aws.amazon.com/s3/home) and create a new bucket.
|
|
|
|
|
2019-03-31 14:02:05 +00:00
|
|
|
![create-bucket](../images/s3-image-upload/create-bucket.png)
|
2016-11-16 06:27:18 +00:00
|
|
|
|
|
|
|
2. Click on bucket, select **Properties** on the side panel, and find **Permission** section. Click **Edit bucket policy**.
|
|
|
|
|
2019-03-31 14:02:05 +00:00
|
|
|
![bucket-property](../images/s3-image-upload/bucket-property.png)
|
2016-11-16 06:27:18 +00:00
|
|
|
|
|
|
|
3. Enter the following policy, replace `bucket_name` with your bucket name:
|
|
|
|
|
2019-03-31 14:02:05 +00:00
|
|
|
![bucket-policy-editor](../images/s3-image-upload/bucket-policy-editor.png)
|
2016-11-16 06:27:18 +00:00
|
|
|
|
2016-11-16 06:46:38 +00:00
|
|
|
```json
|
|
|
|
{
|
|
|
|
"Version": "2012-10-17",
|
|
|
|
"Statement": [
|
|
|
|
{
|
|
|
|
"Effect": "Allow",
|
|
|
|
"Principal": "*",
|
|
|
|
"Action": "s3:GetObject",
|
|
|
|
"Resource": "arn:aws:s3:::bucket_name/uploads/*"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
```
|
2016-11-16 06:27:18 +00:00
|
|
|
|
|
|
|
4. Go to IAM console and create a new IAM user. Remember your user credentials(`key`/`access token`)
|
|
|
|
|
|
|
|
5. Enter user page, select **Permission** tab, look at **Inline Policies** section, and click **Create User Policy**
|
|
|
|
|
2019-03-31 14:02:05 +00:00
|
|
|
![iam-user](../images/s3-image-upload/iam-user.png)
|
2016-11-16 06:27:18 +00:00
|
|
|
|
|
|
|
6. Select **Custom Policy**
|
|
|
|
|
2019-03-31 14:02:05 +00:00
|
|
|
![custom-policy](../images/s3-image-upload/custom-policy.png)
|
2016-11-16 06:27:18 +00:00
|
|
|
|
|
|
|
7. Enter the following policy, replace `bucket_name` with your bucket name:
|
|
|
|
|
2019-03-31 14:02:05 +00:00
|
|
|
![review-policy](../images/s3-image-upload/review-policy.png)
|
2016-11-16 06:27:18 +00:00
|
|
|
|
2016-11-16 06:46:38 +00:00
|
|
|
```json
|
|
|
|
{
|
|
|
|
"Version": "2012-10-17",
|
|
|
|
"Statement": [
|
|
|
|
{
|
|
|
|
"Effect": "Allow",
|
|
|
|
"Action": [
|
|
|
|
"s3:*"
|
|
|
|
],
|
|
|
|
"Resource": [
|
|
|
|
"arn:aws:s3:::bucket_name/uploads/*"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
```
|
2016-11-16 06:27:18 +00:00
|
|
|
|
2016-11-17 10:13:57 +00:00
|
|
|
8. Edit `config.json` and set following keys:
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
{
|
|
|
|
"production": {
|
|
|
|
...
|
2018-01-26 13:00:48 +00:00
|
|
|
"imageuploadtype": "s3",
|
2016-11-17 10:13:57 +00:00
|
|
|
"s3": {
|
|
|
|
"accessKeyId": "YOUR_S3_ACCESS_KEY_ID",
|
|
|
|
"secretAccessKey": "YOUR_S3_ACCESS_KEY",
|
2017-09-23 16:28:57 +00:00
|
|
|
"region": "YOUR_S3_REGION" // example: ap-northeast-1
|
|
|
|
},
|
|
|
|
"s3bucket": "YOUR_S3_BUCKET_NAME"
|
2016-11-17 10:13:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2019-03-31 18:10:32 +00:00
|
|
|
9. In additional to edit `config.json` directly, you could also try [environment variables](../configuration-env-vars.md).
|
2016-11-17 10:13:57 +00:00
|
|
|
|
2016-11-16 06:27:18 +00:00
|
|
|
## Related Tools
|
|
|
|
|
|
|
|
* [AWS Policy Generator](http://awspolicygen.s3.amazonaws.com/policygen.html)
|