Skip to content

Conversation

@Pintorado
Copy link

@Pintorado Pintorado commented Dec 5, 2025

Description

Closes #388
Adds file size and duration validation for Mux video uploads, configurable at both plugin and schema field levels.

Changes

  • File size validation (maxAssetFileSize): Validates before upload using file size (local) or Content-Length header (URLs)
  • Duration validation (maxAssetDuration): Validates by reading video metadata from local files or remote URLs
  • Configuration: Plugin-level defaults with schema field-level overrides via options
  • UX: Validation errors at top of modal, disabled upload button on failure, file size/duration displayed

Testing

Plugin-level configuration

Set validation limits for all mux.video fields globally:

import {muxInput} from 'sanity-plugin-mux-input'

export default defineConfig({
  plugins: [
    muxInput({
      maxAssetFileSize: 1024 * 1024 * 1024, // 1 GB in bytes
      maxAssetDuration: 2 * 60 * 60, // 2 hours in seconds
    }),
  ],
})

Schema-level configuration

You can override the global limits for specific fields, allowing different validation rules for different use cases:

import { defineType, defineField } from "sanity";

export default defineType({
  name: "muxTest",
  title: "Mux Files",
  type: "document",
  fields: [
    defineField({
      name: "shortVideo",
      title: "Short Video (max 1 minute)",
      type: "mux.video",
      options: {
        maxAssetFileSize: 100 * 1024 * 1024, // 100 MB
        maxAssetDuration: 60, // 1 minute
      },
    }),
    defineField({
      name: 'longVideo',
      title: 'Long Video (max 2 hours)',
      type: 'mux.video',
      options: {
        maxAssetFileSize: 1024 * 1024 * 1024, // 1 GB
        maxAssetDuration: 2 * 60 * 60, // 2 hours
      },
    }),
    defineField({
      name: 'unlimitedVideo',
      title: 'Unlimited Video',
      type: 'mux.video',
      // Uses plugin defaults or no validation if not configured
    }),
  ]
})
  • Local files: Upload a file exceeding size/duration limits → validation error appears at top of modal, upload button disabled. Upload valid file → proceeds normally with size and duration displayed.
  • URLs: Paste URL → file size fetched via HEAD request and displayed (or "Unknown size" if unavailable), duration validated from metadata. Invalid URLs show errors, valid ones proceed.
  • Configuration: Set plugin-level defaults → applies to all fields. Override with schema field options → field uses its own limits, overriding plugin config.
  • Edge cases: Servers without Content-Length header → upload continues with "Unknown size". Videos with unreadable metadata → warning logged, upload not blocked.

@vercel
Copy link

vercel bot commented Dec 5, 2025

@Pintorado is attempting to deploy a commit to the Sanity Sandbox Team on Vercel.

A member of the Team first needs to authorize it.

@R-Delfino95 R-Delfino95 self-requested a review December 18, 2025 14:43
@R-Delfino95 R-Delfino95 requested a review from stipsan December 18, 2025 15:18
Copy link
Member

@stipsan stipsan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! 💖

@vercel
Copy link

vercel bot commented Dec 18, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
sanity-plugin-mux-input Ready Ready Preview, Comment Dec 18, 2025 3:52pm
sanity-plugin-mux-input-example Ready Ready Preview, Comment Dec 18, 2025 3:52pm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Video size/duration validation

3 participants