supabase-community / chatgpt-your-files

Production-ready MVP for securely chatting with your documents using pgvector
https://youtu.be/ibzlEQmgPPY
365 stars 126 forks source link

Error uploading to storage. #34

Closed isley-griffith closed 5 months ago

isley-griffith commented 5 months ago

Bug report

Describe the bug

Hello,

After connecting it up to a Supabase project, I am getting the following error when uploading through the application or through the Supabase dashboard:

Failed to upload roman-empire-1.md: insert into "objects" ("bucket_id", "metadata", "name", "owner", "owner_id", "version") values ($1, DEFAULT, $2, DEFAULT, DEFAULT, $3) - null value in column "url" of relation "http_request_queue" violates not-null constraint

I am doing the cloud Supabase version.

To Reproduce

  1. Clone the project (main branch)
  2. Create a new Supabase project
  3. Add the appropriate variables to your .env
  4. Run npm i
  5. Run supabase link --project-ref=<your-ref>
  6. Run npx supabase db push
  7. Run npm run dev and try to upload a .md file.
  8. Alternatively, try to upload a .md file directly to the bucket via the Supabase dashboard.

Expected behavior

To be able to upload a .md file.

Screenshots

image image

System information

clementpeleman commented 5 months ago

What did you do to fix this?

isley-griffith commented 5 months ago

@clementpeleman Make sure you set the secret in the vault.

After replacing with your project-id, run the following:

select vault.create_secret(
  'https://<your-project-id>.supabase.co',
  'supabase_url'
);
clementpeleman commented 5 months ago

Great, thanks! I thought this file did run automatically..

isley-griffith commented 5 months ago

@clementpeleman unfortunately it requires your unique project-id. Quite the headache, this one.

clementpeleman commented 5 months ago

Yes, I see. Thanks for the clarification. I had this configured in the seed.sql file, but not quite sure what that's for then. Maybe some verification if it is using the correct project?

isley-griffith commented 5 months ago

@clementpeleman It is to call the proper edge function.

In this function:

create function private.handle_storage_update()
returns trigger 
language plpgsql
as $$
declare
  document_id bigint;
  result int;
begin
  insert into documents (name, storage_object_id, created_by)
    values (new.path_tokens[2], new.id, new.owner)
    returning id into document_id;

  select
    net.http_post(
      url := supabase_url() || '/functions/v1/process',            <==============
      headers := jsonb_build_object(
        'Content-Type', 'application/json',
        'Authorization', current_setting('request.headers')::json->>'authorization'
      ),
      body := jsonb_build_object(
        'document_id', document_id
      )
    )
  into result;

  return null;
end;
$$;

The proper edge function, "/functions/v1/process" is appended to the supabase_url, which is what you provide to the vault.