ST_Read in @duckdb/duckdb-wasm with user-uploaded File
s
#275
-
I'm currently trying to integrate async function createTable(file: File, db: AsyncDuckDB, tableName: string): Promise<void> {
const conn = await db.connect();
await $db.registerFileHandle(
file.name,
file,
DuckDBDataProtocol.BROWSER_FILEREADER,
true
);
await conn.query(
`INSTALL spatial;
LOAD spatial;
CREATE TABLE ${table_name} AS SELECT * FROM ST_Read('${file.name}');`
);
} My understanding (which is very cursory, just getting going here), is that
I wasn't able to track down this exception in either the In any case, does anyone have experience getting |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
I think you should use BROWSER_FSACCESS instead of BROWSER_FILEREADER. BROWSER_FILEREADER expect basically a blob as input, that can also work for files of limited files if you do the conversion to Uint8Array yourself and then pass that to registerFileHandle. If you manage with BROWSER_FSACCESS great, otherwise I will later set up an example of this. This feature is used by https://shell.duckdb.org via |
Beta Was this translation helpful? Give feedback.
-
Thanks @carlopi! That worked great 😄 I'd be happy to PR an example to this repo or |
Beta Was this translation helpful? Give feedback.
I think you should use BROWSER_FSACCESS instead of BROWSER_FILEREADER.
BROWSER_FILEREADER expect basically a blob as input, that can also work for files of limited files if you do the conversion to Uint8Array yourself and then pass that to registerFileHandle.
If you manage with BROWSER_FSACCESS great, otherwise I will later set up an example of this. This feature is used by https://shell.duckdb.org via
.open
instruction, but following that code is probably a bit too detailed / involved, and this qualify as an example that should be present in the duckdb-wasm readme somehow.