Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Supabase StorageApiError: The resource was not found

I'm trying to download a PDF file from a bucket from a SvelteKit endpoint.

The file is there (I logged filePath and bucketName to the console and checked them against my actual bucket), and I think the policies are correct (although this might be where the mistake is). Regardless, I don't know where I'm going wrong, and it appears I'm doing everything correct as per their documentation.

Here's my code:

import { supabase } from "$lib/js/supabaseClient.js";

async function downloadFile(bucketName, filePath) {
  try {
    const { data, error } = await supabase.storage.from(bucketName).download(filePath);

    if (error) {
      throw error;
    }

    console.log('File downloaded successfully:', data);
    return data;
  } catch (error) {
    console.error('Error downloading file:', error);
    return null;
  }
}

const downloaded_file = await downloadFile("PDF_files", filePath);

And the error message:

Error downloading file: StorageApiError: The resource was not found
    at /Users/<user>/Library/Mobile Documents/com~apple~CloudDocs/Code/Svelte/<app>/node_modules/.pnpm/@[email protected]/node_modules/@supabase/storage-js/dist/main/lib/fetch.js:22:20
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  __isStorageError: true,
  status: 400
}

And the log on Supabase:

Log ID
793bc143-a6ab-47e3-bb48-bff6d88670ed

Log Timestamp (UTC)
2023-04-14T06:37:55.959Z

Log Event Message
GET | 400 | 10.105.42.177 | 7b79f167b38d0b44-AMS | /object/info/PDF_files/e2ab35ee-a24d-4956-8883-43b0c9aa9d1e/3c8229e1-2717-4b07-9add-000d04f39797.pdf | undefined

Log Metadata
[
  {
    "context": [
      {
        "host": <redacted>, 
        "pid": 1
      }
    ],
    "err": [],
    "error": [
      {
        "message": null,
        "postgresError": [
          {
            "code": "PGRST116",
            "details": "Results contain 0 rows, application/vnd.pgrst.object+json requires 1 row",
            "hint": null,
            "message": "JSON object requested, multiple (or no) rows returned"
          }
        ],
        "errno": null,
        "config": [],
        "address": null,
        "status": 406,
        "command": [],
        "body": null,
        "routine": null,
        "expiredAt": null,
        "detail": null,
        "host": null,
        "code": null,
        "syscall": null,
        "validationContext": null,
        "__fault": null,
        "cause": [],
        "__metadata": [],
        "port": null,
        "stack": null,
        "validation": [],
        "hostname": null,
        "severity": null,
        "line": null,
        "httpStatusCode": null,
        "file": null,
        "status_code": null,
        "length": null,
        "metadata": [
          {
            "bucketId": "PDF_files",
            "name": "e2ab35ee-a24d-4956-8883-43b0c9aa9d1e/3c8229e1-2717-4b07-9add-000d04f39797.pdf",
            "names": []
          }
        ],
        "originalError": [],
        "statusCode": null,
        "name": null,
        "error": null
      }
    ],
    "job": [],
    "level": "info",
    "project": "fuphgoftssjnstwjtecp",
    "rawError": null,
    "req": [
      {
        "headers": [
          {
            "accept": null,
            "cf_cache_status": null,
            "cf_connecting_ip": "2a06:98c0:3600::103",
            "cf_ipcountry": null,
            "cf_ray": "7b79f167b38d0b44-AMS",
            "content_length": null,
            "content_location": null,
            "content_range": null,
            "content_type": null,
            "date": null,
            "host": "storage-api-lb-eu-central-1-ext.storage.supabase.com",
            "referer": null,
            "transfer_encoding": null,
            "user_agent": null,
            "x_client_info": null,
            "x_client_trace_id": null,
            "x_forwarded_proto": "https",
            "x_real_ip": null
          }
        ],
        "hostname": "storage-api-lb-eu-central-1-ext.storage.supabase.com",
        "method": "GET",
        "remoteAddress": "10.105.42.177",
        "remotePort": 38672,
        "url": "/object/info/PDF_files/e2ab35ee-a24d-4956-8883-43b0c9aa9d1e/3c8229e1-2717-4b07-9add-000d04f39797.pdf"
      }
    ],
    "reqId": "7b79f167b38d0b44-AMS",
    "res": [
      {
        "statusCode": 400
      }
    ],
    "responseTime": 106.6362340003252,
    "results": [],
    "tenantId": "fuphgoftssjnstwjtecp"
  }
]

And finally my policy on Supabase:

SELECT
Give users access to own folder 3ckb0q_0
INSERT
Give users access to own folder 3ckb0q_1
UPDATE
Give users access to own folder 3ckb0q_2
DELETE
Give users access to own folder 3ckb0q_3

4 policies in PDF_files
like image 309
Koen Avatar asked Oct 28 '25 22:10

Koen


1 Answers

Did you allow public access to the buckets? Some users have faced similar issues in the past because they missed the Select Row Policy. It might be worth checking out this documentation on Storage access control: https://supabase.com/docs/guides/storage/access-control

like image 55
Monica Avatar answered Oct 31 '25 04:10

Monica



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!