FileRef
The FileRef class represents a reference to a file stored in SurrealDB. A file reference consists of a storage bucket name and a unique file key within that bucket.
Source: surrealdb.java
Methods
.getBucket()
Returns the name of the storage bucket containing the file.
Method Syntax
fileRef.getBucket()
Returns: String
.getKey()
Returns the unique key identifying the file within its bucket.
Method Syntax
fileRef.getKey()
Returns: String
Example
Working with file references
import com.surrealdb.Surreal;
import com.surrealdb.Response;
import com.surrealdb.Value;
import com.surrealdb.FileRef;
import com.surrealdb.signin.RootCredential;
try (Surreal db = new Surreal()) {
db.connect("ws://localhost:8000");
db.useNs("surrealdb").useDb("docs");
db.signin(new RootCredential("root", "root"));
Response response = db.query("SELECT avatar FROM user:tobie");
Value result = response.take(0);
if (result.isFile()) {
FileRef file = result.getFile();
String bucket = file.getBucket();
String key = file.getKey();
}
}
See Also