DEV Community

Cover image for Announcing the official Payload Cloud Storage Plugin
James Mikrut for Payload CMS

Posted on • Originally published at payloadcms.com

Announcing the official Payload Cloud Storage Plugin

Payload just released its official Cloud Storage plugin, with support for file storage in AWS S3 and Azure Blob Storage out of the box.

Payload plugins can be insanely powerful, and they're trivial to write thanks to Payload's code-first, config-based nature. We've already seen an impressive array of community plugins, including a few great cloud storage solutions from Richard VanBergen and Alex Bechmann. We're extremely thankful for our community, especially Richard and Alex in regards to their help with cloud storage.

Over the past few months, enterprise clients of ours have asked quite a few times for us to build an officially supported cloud storage plugin, so that all files uploaded to Payload can be stored in the cloud storage provider of their choice. Of course, by default, Payload allows you to store uploads on your own server, but at scale, you might want to offload them to a CDN-backed service for performance and scalability reasons.

So we built a robust, officially supported cloud storage plugin. It's extremely powerful and comes out-of-the-box with Amazon S3 and Azure Blob Storage support. The plugin is built with an adapter-based approach, so you can use it with any cloud storage provider that you wish.

The plugin is available now - check it out on GitHub or NPM!

Usage

Installing and using the plugin is easy. Here's what it looks like to use the S3 adapter:

import { buildConfig } from "payload/config";
import Media from "./collections/Media";
import { cloudStorage } from "@payloadcms/plugin-cloud-storage";
import { s3Adapter } from "@payloadcms/plugin-cloud-storage/s3";

export default buildConfig({
  collections: [Media],
  plugins: [
    // Pass the plugin to Payload
    cloudStorage({
      collections: {
        // Enable cloud storage for Media collection
        media: {
          // Create the S3 adapter
          adapter: s3Adapter({
            config: {
              endpoint: process.env.S3_ENDPOINT,
              credentials: {
                accessKeyId: process.env.S3_ACCESS_KEY_ID,
                secretAccessKey: process.env.S3_SECRET_ACCESS_KEY,
              },
            },
            bucket: process.env.S3_BUCKET,
          }),
        },
      },
    }),
  ],
});
Enter fullscreen mode Exit fullscreen mode

With this plugin, instead of saving files locally to your server, Payload will ship off all uploads, including all automatically resized images, straight to your cloud storage provider.

Adapter-based Implementation

The plugin is built on a simple, yet powerful adapter-based implementation. This means it can be used for any type of cloud storage you need. Out of the box, it comes with Azure Blob Storage and AWS S3 support, but you can easily write your own adapter(s) to host your uploads wherever you need.

Access Control

Payload comes with built-in access control for all uploads. It works seamlessly by re-using your upload-enabled collection's read access control—meaning you can easily restrict who can access which uploads that are stored in your site. This is super powerful in lots of cases, and is a specific strength of Payload over other headless CMS.

Imagine if you had a public Customers collection, and your customers could upload sensitive documents to attach to their profile. You may only want certain users to be able to view these sensitive documents - i.e. admins or the customers themselves. But most people should be denied access.

With Payload, this is built-in. And this plugin fully supports this functionality, so you can build powerful and elegant access control patterns to protect your files—even when they're hosted on your cloud provider.

Get started

Get started by installing the plugin in your Payload app with the following command:

yarn add @payloadcms/plugin-cloud-storage
Enter fullscreen mode Exit fullscreen mode

From there, check out the docs to learn about all the things you can do.

Give Payload a star

If you haven't already, stop by our GitHub page and leave us a star by clicking on the star icon in the top right corner. This helps us grow and gain exposure within the development community.

Request a Plugin

Need a plugin to be created? Join our Discord server and post in the #plugins channel. The Payload team might create it for you, or maybe a community member can help!

Get started in one line

If you haven't yet given the CMS a shot, you can get started free with one command:

npx create-payload-app
Enter fullscreen mode Exit fullscreen mode

Top comments (0)