Files
medusa-store/docs/content/add-plugins/s3.md
Richard Ward db842b7da9 docs: add troubleshooting to medusa-file-s3 plugin (#1952)
* docs: add troubleshooting to medusa-file-s3 plugin

Closes #1943 

This updates the documentation to add some troubleshooting to the medusa-file-s3 plugin documentation.

The fix has been show to work with 2 installations so far - context is here: https://discord.com/channels/876835651130097704/877195433649258536/1003273089284571156

* Update docs/content/add-plugins/s3.md

Co-authored-by: Shahed Nasser <shahednasser@gmail.com>

* Update docs/content/add-plugins/s3.md

Co-authored-by: Shahed Nasser <shahednasser@gmail.com>
2022-08-01 15:07:40 +03:00

110 lines
3.1 KiB
Markdown

# S3
In order to work with images in Medusa, you need a file service plugin responsible for hosting. Following this guide will allow you to upload images to AWS S3.
### Before you start
At this point, you should have an instance of our store engine running. If not, we have a [full guide](https://docs.medusajs.com/tutorial/set-up-your-development-environment) for setting up your local environment.
### Set up AWS
#### Create an S3 bucket
In the AWS console navigate to S3 and create a bucket for your images. Make sure to uncheck "Block _all_ public access".
Additionally, you need to add a policy to your bucket, that will allow public access to objects that are uploaded. Navigate to the permissions tab of your bucket and add the following policy:
```shell=
{
"Id": "Policy1397632521960",
"Statement": [
{
"Sid": "Stmt1397633323327",
"Action": [
"s3:GetObject"
],
"Effect": "Allow",
"Resource": "arn:aws:s3:::YOUR-BUCKET-NAME/*",
"Principal": {
"AWS": [
"*"
]
}
}
]
}
```
Be aware, that this will allow for anyone to acces your bucket. Avoid storing sensitive data.
#### Generate access keys
Navigate to the IAM section of your AWS console and perform the following steps:
- Add a new user with programmatic access
- Add the existing **AmazonS3FullAccess** policy to the user
- Submit the details
Upon successfull creation of the user, you are presented with an **Access key ID** and a **Secret access key**. Note both of them down for later use.
### Installation
First, install the plugin using your preferred package manager:
```bash npm2yarn
npm install medusa-file-s3
```
Then configure your `medusa-config.js` to include the plugin alongside the required options:
```=javascript
{
resolve: `medusa-file-s3`,
options: {
s3_url: "https://s3-guide-test.s3.eu-west-1.amazonaws.com",
bucket: "test",
region: "eu-west-1"
access_key_id: "YOUR-ACCESS-KEY",
secret_access_key: "YOUR-SECRET-KEY",
},
},
```
In the above options, an `s3_url` is included. The url has the following format:
```shell=
https://[bucket].s3.[region].amazonaws.com
```
The two access keys in the options are the ones created in the previous section.
:::tip
Make sure to use an environment variable for the secret key in a live environment.
:::
:::caution
If you have multiple storage plugins configured, the last plugin declared in the `medusa-config.js` file will be used.
:::
### Try it out
Finally, run your Medusa server alongside our admin system to try out your new file service. Upon editing or creating products, you can now upload thumbnails and images, that are stored in an AWS S3 bucket.
### Troubleshoot Errors
#### The bucket does not allow ACLs
If the backend file upload fails with this message then you need to enable ACLs on your S3 bucket.
To do this,
- Go to the `Bucket -> Permissions` tab
- Scroll to `Object Ownership` and click `edit`
- Select `ACLs enabled` and `Bucket owner preferred`
- Click the `Save Changes`
File uploads should now work.