DEV Community

Nomodo.io
Nomodo.io

Posted on • Originally published at blog.nomodo.io on

How to Configure MinIO Plugin for File Storage in MedusaJS Locally

Prerequisites

  • Knowledge of environment variables
  • Installed MedusaJS project
  • Access to Nomodo.io for receiving MinIO credentials

TL;DR

  1. Set up environment variables.
  2. Install the MinIO plugin via npm.
  3. Add the plugin to your Medusa config file.
  4. Test the configuration locally.

Step 1: Set Up Environment Variables

To connect your local Medusa project to MinIO for file storage, you'll need certain environment variables. These are provided by Nomodo.io when you set up your instance. Here's an example of what the environment variables might look like:

MINIO_ENDPOINT="https://s3.nomodo.io/your-instance-id"
MINIO_BUCKET="your-instance-id"
MINIO_ACCESS_KEY="your-access-key"
MINIO_SECRET_KEY="your-secret-key"
Enter fullscreen mode Exit fullscreen mode

Note: You will receive the actual values for these variables from Nomodo. Do not use the placeholders above.

Add these values to your local .env file. This will allow Medusa to use them during local development.

Example .env file:

MINIO_ENDPOINT="https://s3.nomodo.io/medcs0elg85iop2o82rj3n0"
MINIO_BUCKET="medcs0elg85iop2o82rj3n0"
MINIO_ACCESS_KEY="Your_Access_Key_Here"
MINIO_SECRET_KEY="Your_Secret_Key_Here"
Enter fullscreen mode Exit fullscreen mode

Step 2: Install the MinIO Plugin

Next, you'll need to install the medusa-file-minio plugin, which adds support for MinIO as a file storage solution for your Medusa backend.

Use npm to install the plugin by running:

npm install medusa-file-minio
Enter fullscreen mode Exit fullscreen mode

This plugin enables your Medusa backend to seamlessly upload and store files on your MinIO instance. For further information and advanced configuration options, check out the official medusa-file-minio plugin documentation.

Step 3: Add MinIO Plugin to Your Medusa Configuration

Once the plugin is installed, you’ll need to configure it by adding it to your Medusa config file. Open your Medusa configuration file (medusa-config.js or medusa-config.ts), and include the following code:

{
  resolve: 'medusa-file-minio',
  options: {
    endpoint: process.env.MINIO_ENDPOINT,
    bucket: process.env.MINIO_BUCKET,
    access_key_id: process.env.MINIO_ACCESS_KEY,
    secret_access_key: process.env.MINIO_SECRET_KEY,
  },
},
Enter fullscreen mode Exit fullscreen mode

This configuration allows Medusa to use the MinIO plugin for file storage, leveraging the environment variables you defined earlier.

Step 4: Test the Local Setup

After configuring the plugin, it’s time to test if everything is working correctly. Start your local Medusa server:

npm run dev
Enter fullscreen mode Exit fullscreen mode

Now, try uploading a file through the Medusa admin panel or your store’s frontend. If everything is configured properly, the file should be successfully uploaded to your MinIO bucket.

Troubleshooting : If the file upload fails, ensure that the environment variables are correctly set and check the logs for errors. Also, verify that your access keys and secrets are valid.

Deploy—put it live

Once your changes are ready, commit and push them to the remote repository:

git add .
git commit -m "Your message"
git push origin master
Enter fullscreen mode Exit fullscreen mode

Copy these ENV variables into Settings > Environment Variables app detail. After you’ve filled in all the variables, press the “Reload” button, which will run a new deployment in the background. Until the deployment is complete, the Medusa.js backend will not be available, but don’t worry, it will only take a few seconds.

Conclusion

Setting up file storage for your MedusaJS store using the MinIO plugin locally is a straightforward process. With the environment variables provided by Nomodo.io and a quick plugin installation, you’ll be ready to handle file uploads seamlessly.

This setup allows you to offload file management to MinIO’s robust storage infrastructure while keeping your Medusa backend clean and efficient. Try it out, and if you need more help, don’t hesitate to reach out to the Nomodo support team!

Try Medusa.js

Use code B0OZUUYW for a discount. We 💙 our readers.

Start Medusa.js free trial

Top comments (0)