Strapi + Railway Bucket
sdebie
PROOP

10 months ago

Has anyone tried using Strapi CMS with Railway Bucket?

Solved

6 Replies

coderillusionist
PRO

10 months ago

Hi, yes. You can use the S3 bucket plugin by Strapi, works like a train 🚂 !


sdebie
PROOP

10 months ago

And using presigned URLs?

I tried the plugin.

    "@strapi/provider-upload-aws-s3": "5.18.1",

But stuck on CORS block

Access to fetch at 'https://my-bucket.storage.railway.app/IMG_1242_95198ad9a2.jpeg' from origin 'https://my-strapi app.up.railway.app' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

coderillusionist

Hi, yes. You can use the S3 bucket plugin by Strapi, works like a train 🚂 !

sdebie
PROOP

10 months ago

And using presigned URLs?

I tried the plugin.

    "@strapi/provider-upload-aws-s3": "5.18.1",

But stuck on CORS block

Access to fetch at 'https://my-bucket.storage.railway.app/IMG_1242_95198ad9a2.jpeg' from origin 'https://my-strapi app.up.railway.app' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Thanks in advance for the support!


coderillusionist
PRO

10 months ago

Did you configure Strapi’s CORS headers?


coderillusionist

Did you configure Strapi’s CORS headers?

sdebie
PROOP

10 months ago

Yes but I'm fairly new to this... could you walk me through it?

Stack:

  • Strapi on Railway (from template)
  • Railway Storage Bucket

I installed @strapi/provider-upload-aws-s3.

  • Can you confirm that I should use presigned URL's for upload?
  • How to configure CORS policy on the Railway bucket?

sdebie
PROOP

10 months ago

Never mind I figured it out 😄

>>

# Railway Bucket Storage with Strapi Setup Guide

## Prerequisites

- Strapi v5 project @strapi/strapi@5.33.0)

- Railway account with Bucket Storage

- Node.js 18+ (preferably 22.x via NVM)

- PostgreSQL database

## Quick Setup

### 1. Install Required Packages

npm install @strapi/provider-upload-aws-s3@5.33.0

### 2. Environment Configuration

# Database Configuration
DATABASE_URL=postgresql://postgres:your-password@switchyard.proxy.rlwy.net:53600/railway

# AWS S3 Configuration (Railway Bucket)
AWS_ACCESS_KEY_ID=your_access_key_from_railway
AWS_SECRET_ACCESS_KEY=your_secret_key_from_railway
AWS_REGION=ams
AWS_BUCKET=your-bucket-name-from-railway
AWS_ENDPOINT=https://storage.railway.app

# Strapi Security Secrets
JWT_SECRET=your-generated-jwt-secret
ADMIN_JWT_SECRET=your-generated-admin-jwt-secret
API_TOKEN_SALT=your-generated-api-token-salt
TRANSFER_TOKEN_SALT=your-generated-transfer-token-salt
APP_KEYS=key1,key2,key3

# Server Configuration
HOST=0.0.0.0
PORT=1337
URL=http://localhost:1337

# AWS S3 Settings (Railway Private Bucket)
AWS_ACL=private
AWS_SIGNED_URL_EXPIRES=900

### 3. Configure Strapi Plugins

Update config/plugins.js:

module.exports = ({ env }) => ({
"users-permissions": {
config: {
jwtSecret: env("JWT_SECRET"),
    },
  },
upload: {
config: {
provider: "aws-s3",
providerOptions: {
s3Options: {
credentials: {
accessKeyId: env("AWS_ACCESS_KEY_ID"),
secretAccessKey: env("AWS_SECRET_ACCESS_KEY"),
          },
region: env("AWS_REGION"),
endpoint: env("AWS_ENDPOINT"),
forcePathStyle: true,
params: {
ACL: env("AWS_ACL", "private"),
signedUrlExpires: env("AWS_SIGNED_URL_EXPIRES", 15 * 60),
Bucket: env("AWS_BUCKET"),
          },
        },
      },
actionOptions: {
upload: {},
uploadStream: {},
delete: {},
      },
    },
  },
});

### 4. Update Content Security Policy

Update config/middlewares.js to allow Railway storage URLs:

module.exports = [
"strapi::errors",
  {
name: "strapi::security",
config: {
contentSecurityPolicy: {
useDefaults: true,
directives: {
"connect-src": ["'self'", "https:"],
"img-src": [
"'self'",
"data:",
"blob:",
"dl.airtable.com",
"https://storage.railway.app",
          ],
"media-src": [
"'self'",
"data:",
"blob:",
"dl.airtable.com",
"https://storage.railway.app",
          ],
upgradeInsecureRequests: null,
        },
      },
    },
  },
"strapi::cors",
"strapi::poweredBy",
"strapi::logger",
"strapi::query",
"strapi::body",
"strapi::session",
"strapi::favicon",
"strapi::public",

];

Status changed to Solved chandrika • 9 months ago


Welcome!

Sign in to your Railway account to join the conversation.

Loading...