-
Notifications
You must be signed in to change notification settings - Fork 516
Description
Describe the bug
Drag-and-drop image upload fails with error "The following item can't be uploaded because there's no known conversion from content type to array item" when an array field contains both image type members and custom object type members.
To Reproduce
Schema:
// Custom object type (not image or file)
defineType({
name: 'video',
type: 'object',
fields: [
defineField({ name: 'muxVideo', type: 'mux.video' }),
defineField({ name: 'caption', type: 'string' })
]
})
// Array mixing image and object types
defineType({
name: 'work',
type: 'document',
fields: [
defineField({
name: 'images',
type: 'array',
of: [
{type: 'image'}, // or custom image type
{type: 'video'} // custom object - breaks upload
]
})
]
})Steps:
- Create document with mixed-type array as above
- Drag JPEG file onto the array field
- Error appears instead of upload
Expected behavior
Upload resolver should:
- Recognize the dragged file is an image
- Match it to the
imagearray member type - Upload successfully to that member
Actual behavior
Error dialog: "The following item can't be uploaded because there's no known conversion from content type to array item: filename.jpg (image/jpeg)"
Upload via Browse button works fine.
Root cause (investigation)
The upload resolver in getUploadCandidates() iterates all array member types and calls resolveUploader(memberType, file) for each. When it encounters the video object type:
// From node_modules/sanity/lib/index.js
function resolveUploader(type, file) {
return uploaders.find((uploader) =>
is$1(uploader.type, type) && // Checks if type is 'image' or 'file'
accepts(file, uploader.accepts) &&
accepts(file, type.options?.accept || "")
) || null;
}The is$1('image', videoObjectType) fails because the custom object doesn't extend image or file. This causes resolveUploader to return null for the object member. If ANY member returns null, the entire drop is rejected.
Workaround
Remove object types from arrays that need drag-and-drop:
of: [{type: 'image'}] // WorksUse separate fields for non-image/file content.
Environment
- Sanity Studio: v5.7.0
- React: v19.1
- Browser: Chrome 131
Impact
Cannot use drag-and-drop with mixed content galleries (images + videos, images + embeds, etc.). Must split into separate arrays or use Upload button.