1.2.1 • Published 4 years ago

tinacms-file-field v1.2.1

Weekly downloads
34
License
MIT
Repository
github
Last release
4 years ago

tinacms-file-field Known Vulnerabilities NPM

Adds a file field to TinaCMS

Article

If you want to read more in depth walk through to how this file field works, checkout my article here: https://mintel.me/how-to-add-a-file-upload-to-your-gatsby-site/

Preview

Example

Install

npm install --save tinacms-file-field

or

yarn add tinacms-file-field

Manual

import TinaCMSFileField from 'tinacms-file-field'

const fileField = new TinaCMSFileField(tinacms);

fileField.install();

with Gatsby

add to gatsby-browser.js

import TinaCMSFileField from 'tinacms-file-field'

export const onClientEntry = () => {
  const fileField = new TinaCMSFileField(window.tinacms);
  fileField.install();
}

Usage

The file component is applied when specifying component: 'file' in your field.

Examples

{
  name: 'frontmatter.file',
  component: 'file',
  description: 'This is a pdf upload field',
  label: 'PDF',
},

You can also specify to accept only specific MIME types, change the default upload dir or disallow clearing.

{
  name: 'frontmatter.file',
  component: 'file',
  description: 'This is a pdf upload field',
  label: 'PDF',
  accept: 'application/pdf',
  clearable: true,
  parse: (file) => `../uploads/${file}`,
  uploadDir: () => 'src/uploads',
},