Skip to content

Commit cf5be30

Browse files
Add example for FileStore-API / TileDB-Cloud interaction
1 parent f2c984b commit cf5be30

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package examples.io.tiledb.java.api;
2+
3+
import io.tiledb.java.api.Array;
4+
import io.tiledb.java.api.ArraySchema;
5+
import io.tiledb.java.api.Config;
6+
import io.tiledb.java.api.Context;
7+
import io.tiledb.java.api.FileStore;
8+
import io.tiledb.java.api.MimeType;
9+
import io.tiledb.java.api.TileDBError;
10+
11+
public class FileStoreExample {
12+
public static void main(String[] args) throws TileDBError {
13+
// Set up the config with your TileDB-Cloud credentials
14+
Config config = new Config();
15+
// For s3 access
16+
config.set("vfs.s3.aws_access_key_id", "<ID>");
17+
config.set("vfs.s3.aws_secret_access_key", "<KEY>");
18+
19+
// For TileDB-Cloud access.
20+
// You can either use rest.username and rest.password
21+
config.set("rest.username", "<USERNAME>");
22+
config.set("rest.password", "<PASSWORD>");
23+
24+
// Or rest.token
25+
config.set("rest.token", "<TOKEN>");
26+
27+
Context ctx = new Context(config);
28+
29+
// Create the array schema of an array based on the file to be saved
30+
ArraySchema arraySchema = FileStore.schemaCreate(ctx, "<FILENAME>");
31+
32+
// Create a TileDB array with the schema
33+
Array.create("tiledb://<NAMESPACE_NAME>/s3://<BUCKET_NAME>/<ARRAY_NAME>", arraySchema);
34+
35+
// Import the file to be saved to the TileDB array
36+
FileStore.uriImport(
37+
ctx,
38+
"tiledb://<NAMESPACE_NAME>/<ARRAY_NAME>",
39+
"<FILENAME>",
40+
MimeType.TILEDB_MIME_AUTODETECT);
41+
42+
// Export/download the file from TileDB and save it with a given name. Use s3 link for this
43+
// operation!
44+
FileStore.uriExport(ctx, "s3://<BUCKET_NAME>/<ARRAY_NAME>", "<OUTPUT_FILENAME>");
45+
}
46+
}

0 commit comments

Comments
 (0)