DrMint

payloadcms sftp storage

by DrMint
Cloud storage
v?

Overview

Summary generated from the README

An SFTP adapter for the Payload cloud-storage plugin that stores collection uploads on a remote server over SSH. It uses ssh2-sftp-client for the connection and file operations. Configure it per collection with connection options, a destination root path and a public endpoint.

Features

  • Stores uploads on a remote server over SFTP
  • Authenticates with a private key and passphrase or a password
  • Supports a custom port, defaulting to 22
  • Places files in a subfolder named after the collection slug
  • Deletes the remote file when the Payload entry is deleted

Use cases

  • Store media uploads on an existing server reachable only through SFTP
  • Serve videos from a self-managed host instead of object storage such as S3

From the author

SFTP adapter for Payload CMS's plugin-cloud-storage plugin

Installation

npm i payloadcms-sftp-storage

2

Stars

0

Forks

0

Open Issues

2 years ago

Last Updated

0

Weekly Downloads

v1.0.1

npm Version

6.6 KB

Unpacked Size

3

Dependencies

GitHub stars

Trends appear after 7 days of data. Daily snapshots have not started yet.

npm weekly downloads

Trends appear after 7 days of data. Daily snapshots have not started yet.

Each point is npm's rolling 7-day download count.

Health Score

27/100Fair

Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.

Badge for your README

Payload Directory health badge
Markdown
[![Payload Directory](https://payloaddirectory.dev/badge/782753635-root.svg)](https://payloaddirectory.dev/plugins/782753635-root)
HTML
<a href="https://payloaddirectory.dev/plugins/782753635-root"><img src="https://payloaddirectory.dev/badge/782753635-root.svg" alt="Payload Directory"></a>
Updated Apr 6, 2024Created Apr 6, 2024Published Apr 6, 2024

README

PayloadCMS SFTP Storage Adapter

SFTP adapter for Payload CMS's plugin-cloud-storage plugin

This adapter uses ssh2-sftp-client to handle the SSH connection and SFTP operations.

Usage

Let's say we have a Videos collection (which slug is "videos") and we want to store the uploads on a third-party remote storage using SFTP.

At the top of your payload.config.ts file, add the following:

import { sftpAdapter } from "payloadcms-sftp-storage";

Then within the buildConfig add the following:

plugins: [
  cloudStorage({
    collections: {
      videos: {
          adapter: sftpAdapter({
          connectOptions: {
              host: "domain.com",
              username: "userName",
              privateKey: process.env.SFTP_PRIVATE_KEY, // See bellow how to add a privatekey in .env file
              passphrase: 'a pass phrase for the private key'

              // Instead of a private key you can also use a password:
              // password: "mypassword",

              // You may set a custom port (default: 22)
              // port: 2207,
          },
          destinationPathRoot: "/absolute/path/to/destination/root/folder",
          publicEndpoint: "https://domain.com",
        }),
        disableLocalStorage: true,
        disablePayloadAccessControl: true,
      },
    },
  }),
],

If we upload a video file name "my-video.mp4", the file will be uploaded at destinationPathRoot, in a subfolder named "videos" (because this is the slug of the collection) as a file with the same name as the original "my-video.mp4". In this example, the path of the transfered file will be /absolute/path/to/destination/root/folder/videos/my-video.mp4, and its public address will be https://domain.com/videos/my-video.mp4

Beware: when deleting an entry, the file will also be deleted on the remote storage. Also, if a file "my-video.mp4" already exists, and we try to upload another file with the same name, the original file will be overwritten.

About the Private Key

It's a bit tedious to use a private key. You can't use fs within PayloadCMS config file without resorting to some webpack shenanigans. So instead, here's how to store the private key in a .env variable:

Run this command:

echo "SFTP_PRIVATE_KEY=\"`sed -E 's/$/\\\n/g' /path/to/my_private_key`\"" >> /path/to/.env

Then open your .env file and edit the variable into a single line.

Similar plugins