Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manually configure asset sources not working #146

Open
shabith opened this issue May 31, 2024 · 1 comment
Open

Manually configure asset sources not working #146

shabith opened this issue May 31, 2024 · 1 comment

Comments

@shabith
Copy link

shabith commented May 31, 2024

Describe the bug

I tried to disable the asset source for a specific schema following the Manually configure asset sources section in README but it is not working.

To Reproduce

Steps to reproduce the behavior:

  1. Create a schema with field type image called movie-image
  2. Try to remove unsplash as asset source for that schema adding following code to the config
import { unsplashImageAsset, unsplashAssetSource } from 'sanity-plugin-asset-source-unsplash'

export default defineConfig({
  // ...
  plugins: [unsplashImageAsset()],
  form: {
    image: {
      assetSources: (previousAssetSources, { schema }) => {
        if (schema.name === 'movie-image') {
          // remove unsplash from movie-image types
          return previousAssetSources.filter((assetSource) => assetSource !== unsplashAssetSource)
        }
        return previousAssetSources
      },
    },
  },
})

Expected behavior

movie-image shouldn't have unsplash as in source dropdown

Which versions of Sanity are you using?

@sanity/cli (global) 3.29.1 (latest: 3.44.0)
@sanity/astro 3.0.0 (latest: 3.1.3)
@sanity/code-input 4.1.4 (up to date)
@sanity/vision 3.41.1 (latest: 3.44.0)
sanity 3.41.1 (latest: 3.44.0)

What operating system are you using?

Which versions of Node.js / npm are you running?

10.5.0
v20.11.0

Additional context

When I console log schema.name it returns undefined

@eduardonwa
Copy link

eduardonwa commented Feb 11, 2025

can't believe it's been a year and no response... i am too having the same issue.

here's more information: https://www.sanity.io/docs/custom-asset-sources#8a7448076430

you can have something like this on the sanity config

form: {
    image: {
      assetSources: (prev) => [...prev, unsplashAssetSource],
      directUploads: true,

on your image fields, if you want to allow both types of sources, you don't have to do anything because it will inherit this setting. if you only want from the computer use

options: {
 sources: [] // empty array
}

this will allow custom uploads but it will not bring the "static array" aka the previously uploaded images. couldn't figure that part.

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

No branches or pull requests

2 participants