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

Directus provider not working #1423

Open
BorisKamp opened this issue Aug 8, 2024 · 3 comments
Open

Directus provider not working #1423

BorisKamp opened this issue Aug 8, 2024 · 3 comments

Comments

@BorisKamp
Copy link

BorisKamp commented Aug 8, 2024

Hi!

Using "@nuxt/image": "^1.7.0" and "nuxt": "^3.12.4", I have the following setup for nuxt image: nuxt.config.ts`:

  modules: [
    ...
    '@nuxt/image',
    ...
  ],
  image: {
    directus: {
      baseUrl: 'http://localhost:8055/assets/',
    },
  },
....

A page with the following content:

<script lang="ts" setup>
</script>

<template>
  <div class="flex min-h-screen flex-1">
    <div class="flex flex-1 flex-col justify-center px-4 py-12 sm:px-6 lg:flex-none lg:px-20 xl:px-24">
      <div class="mx-auto w-full max-w-sm lg:w-96">
        <slot />
      </div>
    </div>
    <div class="relative hidden w-0 flex-1 lg:block">
      <NuxtImg
        provider="directus"
        src="45200248-cebf-4d57-b7f5-aee8f2351289"
        class="absolute inset-0 h-full w-full object-cover"
      />
    </div>
  </div>
  <TailwindIndicator />
</template>

However, when I view the frontend I get the following error: GET http://localhost:3000/45200248-cebf-4d57-b7f5-aee8f2351289 404 (Page not found: /45200248-cebf-4d57-b7f5-aee8f2351289) and [Vue Router warn]: No match found for location with path "/45200248-cebf-4d57-b7f5-aee8f2351289"

The file is there, when I view http://localhost:8055/assets/45200248-cebf-4d57-b7f5-aee8f2351289.jpeg in my browser it shows the file.....

Whats up here?

@Max-Kucher
Copy link

I have the same error when using strapi:

nuxt.config.js

 ...
  image: {
    format: ['avif'],
    providers: {
      strapi: {
        baseURL: process.env.NUXT_ENV_SITE_BACKEND_URL, // Has http://127.0.0.1 value
      },
    },
  },
  ...

But my NuxtPicture, NuxtImg and useImage still generates:
http://localhost:1337/uploads/image.jpg

@BorisKamp
Copy link
Author

Hi guys!

Anybody here who can fix this? Definitely seems like a bug to me right?

@BorisKamp
Copy link
Author

BorisKamp commented Sep 11, 2024

For anybody encountering the same, for now I use without a provider like this:

      <NuxtImg
        v-if="settings?.auth_cover_image"
        :src="filePath(settings?.auth_cover_image, '?width=2000')"
        :placeholder="filePath(settings?.auth_cover_image, '?width=10')"
        loading="lazy"
        class="absolute inset-0 h-full w-full object-cover"
      />

My filePath composable looks like this:

export function filePath(file: DirectusFile, transformations?: string, format: string | null = 'webp') {
  let queryStr = transformations

  if (!file.filename_download || !file.id) { return null }

  if (queryStr && format) {
    queryStr = `${queryStr}&format=${format}`
  }
  else if (format) {
    queryStr = `?format=${format}`
  }
  else {
    queryStr = ''
  }
  return `${useRuntimeConfig().public.apiHost}/assets/${file?.id}/${encodeURIComponent(file?.filename_download)}${queryStr}`
}

This works perfectly fine as well....

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