File
class File
A non-tabular file on Redivis, belonging to a file index table (or referenced by a query's results). Files can be read into memory, streamed, or downloaded.
Constructors
Table.file(path)
Return the File at a path within a file index table.
Table.listFiles([maxResults, options])
List the Files in a file index table.
Query.file(path)
Return the File at a path within a query's results.
Query.listFiles([maxResults, options])
List the Files referenced by a query's results.
Directory.get(path)
Return the File at a path within a Directory.
Directory.list([maxResults, options])
List the Files (and subdirectories) of a Directory.
Examples
// See https://redivis.com/datasets/yz1s-d09009dbb/files for example data
const table = redivis.table('demo.example_data_files:yz1s:v1_3.example_file_types:4c10');
const textFile = await table.file('pandas_core.py');
const imageFile = await table.file('bogota.tiff');
// Read file contents
const text = await textFile.read({ asText: true });
const bytes = await imageFile.read(); // A Uint8Array
const firstBytes = await imageFile.read({ startByte: 0, endByte: 99 }); // The first 100 bytes
// Stream the file's contents (e.g., to a WritableStream)
await textFile.stream().pipeTo(writableStream);
// In the browser, display an image
const blob = await new Response(imageFile.stream()).blob();
img.src = URL.createObjectURL(blob);
// Download the file (Node.js only)
await imageFile.download('./path/'); // Downloaded as ./path/bogota.tiff
await textFile.download('./path/renamed.txt'); // Downloaded as ./path/renamed.txtAttributes
id
The file's id.
name
The file's name, e.g. a.png.
path
The file's path within its table, e.g. images/a.png.
size
The file's size, in bytes.
md5Hash
The base64-encoded MD5 hash of the file's contents.
addedAt
When the file was added to its table.
directory
The Directory that contains the file, if it was listed via a directory.
table
The Table that the file belongs to, if any.
query
The Query that the file belongs to, if any.
properties
An object containing the file's metadata, as listed in its table.
Methods
File.download([path, options])
Download the file (Node.js only).
File.read([options])
Read the file's contents into memory.
File.stream([options])
Return a ReadableStream of the file's contents.
Was this helpful?

