0

我无法从 supabase 下载图像。我得到这个错误

{
"statusCode": "400",
"error": "Bad Request",
"message": "headers should have required property 'authorization'"
}

我已经关注了文档 https://supabase.io/docs/guides/with-nextjs

这是我的请求代码

const myQuote = ({ dataFetch }) => {
  const [avatarUrl, setAvatarUrl] = useState(null);

  async function downloadImage(path) {
    try {
      const { data, error } = await supabase.storage
        .from("job-photo")
        .download(`jobphotos/${path}.jpg`);
      if (error) {
        throw error;
      }
      const url = URL.createObjectURL(data);
      setAvatarUrl(url);
    } catch (error) {
      console.log("Error downloading image: ", error.message);
    }
  }

  return (
    <>
      <Dashboard />
      <QuoteTable tableData={dataFetch} downloadImg={downloadImage} />
    </>
  );
};

export default myQuote;
4

2 回答 2

1

public/通过添加到 from设法让它工作

 const { data, error } = await supabase.storage
        .from("public/job-photo")
        .download(`jobphotos/${path}.jpg`);
于 2021-11-13T11:32:44.340 回答
0

你有以下代码吗?

import { createClient } from '@supabase/supabase-js'

const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL
const supabaseAnonKey = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY

export const supabase = createClient(supabaseUrl, supabaseAnonKey)
于 2021-11-13T11:05:45.550 回答