duckdb / duckdb-wasm

WebAssembly version of DuckDB
https://shell.duckdb.org
MIT License
1.03k stars 113 forks source link

Spatial Remote Access is not working in WASM for Excel Files #1578

Closed alperdincer closed 5 months ago

alperdincer commented 6 months ago

What happens?

I'm trying to get Excel Data via the following command.

CREATE TABLE unicef_remote AS SELECT * FROM st_read('https://your.domain.com/test.xlsx', layer = 'Sheet2', open_options=['HEADERS=FORCE']);

This query is working on the local NodeJS, but it is not working on the WASM version.

I got the following error when I run the query :

IO Error: GDAL Error (4): Failed to open file https://your.domain.com/test.xlsx: Opening file 'https://your.domain.com/test.xlsx' failed with error: NetworkError: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'https://your.domain.com/test.xlsx'.

To Reproduce

CREATE TABLE unicef_remote AS SELECT * FROM st_read('https://your.domain.com/test.xlsx', layer = 'Sheet2', open_options=['HEADERS=FORCE']);

Browser/Environment:

Chromium 120.0.6099

Device:

MacOS

DuckDB-Wasm Version:

1.28.1-dev81.0

DuckDB-Wasm Deployment:

https://shell.duckdb.org/

Full Name:

Alper Dincer

Affiliation:

None

carlopi commented 5 months ago

I would assume this to be related to CORS settings, can you try to host your file either on github-pages, on regular github (accessing it like FROM st_read('https://raw.githubusercontent.com/ORG_NAME/REPO_NAME/main/PATH/TO/FILE_NAME.xlxs) or on S3 while granting access from CORS?

S3-hosted example:

LOAD spatial;
FROM st_read('https://duckdb-blobs.s3.amazonaws.com/data/test.xlsx');

Link: https://shell.duckdb.org/#queries=v0,LOAD-spatial~,FROM-st_read('https%3A%2F%2Fduckdb%20blobs.s3.amazonaws.com%2Fdata%2Ftest.xlsx')~

Where the bucket has permission set up like:

[
    {
        "AllowedHeaders": [
            "Content-Length",
            "Authorization"
        ],
        "AllowedMethods": [
            "GET",
            "HEAD"
        ],
        "AllowedOrigins": [
            "*"
        ],
        "ExposeHeaders": []
    }
]
alperdincer commented 5 months ago

Thanks @carlopi. Yes you are right. When I change my CORS settings, it will worked.

As you created "CORS error" will be good for users to understand what's going on behind.