Sanity v3: File type options.accept causes "split is not a function" error

4 replies
Last updated: May 31, 2023
[Sanity v3 bug?] File type options.accept: when I click the “Browse” button, the desk tool crashed with error: “*Error: accept.split is not a function*”. The error goes away when I remove the options.accept.
Schema:


{

name: "document",

type: "file",

title: "Document",

options: {

accept: [

"application/pdf",

],

},

}

My previous Sanity v2 projects are fine.

Does anyone know how to get it resolved? Thanks.
AI Update

You're running into the accept.split is not a function error because the options.accept property needs to be a string, not an array. According to the Sanity file type documentation, the accept option should be formatted as a string that matches the HTML accept attribute specification.

Here's the fix for your schema:

{
  name: "document",
  type: "file",
  title: "Document",
  options: {
    accept: "application/pdf", // String instead of array
  },
}

If you need to accept multiple file types, use a comma-separated string:

{
  name: "document",
  type: "file",
  title: "Document",
  options: {
    accept: "application/pdf,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document",
  },
}

Why this format? The accept option is passed directly to the underlying HTML <input type="file"> element's accept attribute, which expects a comma-separated string of valid file type specifiers according to web standards. The documentation recommends using MIME types (like "application/pdf") over file extensions (like ".pdf") for better drag-and-drop hover notifications.

This same format applies to the image type as well - if you have image fields with options.accept, they should also use comma-separated strings rather than arrays.

Show original thread
4 replies
I think ‘accept’ expects a string not an array of strings
Thank you. Weird that I had it wrong in my previous projects.
user N
I could be wrong, but I believe both were handled in v2 (a string or an array of strings), but in v3 we tightened it up to align with what was documented (i.e., only a string). So I don’t think it’s that you were wrong before, but perhaps that we didn’t enforce it.
That makes sense. Thanks
user A
!!

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?