Skip to content

Append a hash to upload filenames in Payload CMS, and optimize your CDN caching strategy

License

Notifications You must be signed in to change notification settings

jeanbmar/payload-hash-upload

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Append a hash to upload filenames in Payload CMS, and optimize your CDN caching strategy

This plugin ensures safe filenames with Payload CMS database.
Resized images are properly supported.

Install

npm install payload-hash-upload

Get Started

Enable plugin in Payload CMS config

import { buildConfig } from 'payload/config';
import hashUpload from 'payload-hash-upload';

export default buildConfig({
  // ...
  plugins: [
      hashUpload,
  ],
});

Configure your upload collections

const Media = {
  slug: 'media',
  upload: {
    staticURL: '/assets',
    staticDir: 'assets',
    hash: {
      algorithm: 'md5', // any algo compatible with Node.js crypto.createHash
      truncate: 10, // optional, for shorter hashes
    },
  },
};

export default Media;

Result

chnux.png -> chnux.9cdfb439c7.png

About

Append a hash to upload filenames in Payload CMS, and optimize your CDN caching strategy

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published