Options
All
  • Public
  • Public/Protected
  • All
Menu

File objects are used for uploading data and then reusing as part of Dataset graph visualizations

Powerfully, the same file may be reused in multiple Datasets, so many variants can be made cheaply and quickly.

For configuring supported file formats, see https://hub.graphistry.com/docs/api/2/rest/files/ .




example

Upload an EdgeFile from a JSON object in a columnar form

import { EdgeFile } from '@graphistry/node-api';
const edgesFile = new EdgeFile(
{
's': ['a', 'b', 'c'],
'd': ['d', 'e', 'f'],
'v': ['v1', 'v2', 'v3']
}
);
await edgesFile.upload(client);
console.log(`EdgeFile uploaded as ID ${edgesFile.fileID}`);

example

Upload an EdgeFile from a JSON object in a row-oriented form

import { EdgeFile } from '@graphistry/node-api';
const edgesFile = new EdgeFile(
[
{'s': 'a', 'd': 'd', 'v': 'v1'},
{'s': 'b', 'd': 'e', 'v': 'v2'},
{'s': 'c', 'd': 'f', 'v': 'v3'}
],
'json',
'my nodes file',

// JSON parsing options:
// - https://hub.graphistry.com/docs/api/2/rest/upload/data/#uploadjson2
// - https://pandas.pydata.org/docs/reference/api/pandas.read_json.html
//
// Also: file_compression, sql_transforms, ...
// https://hub.graphistry.com/docs/api/2/rest/files/
{parser_options: {orient: 'records'}}

);
await edgesFile.upload(client);
console.log(`EdgeFile uploaded as ID ${edgesFile.fileID}`);

example

Upload an EdgeFile using promises

import { EdgeFile } from '@graphistry/node-api';
const edgesFile = new EdgeFile({'s': ['a', 'b', 'c'], 'd': ['d', 'e', 'f'], 'v': ['v1', 'v2', 'v3']});
edgesFile.upload(client).then(
() => console.log(`EdgeFile uploaded as ID ${edgesFile.fileID}`)
).catch(err => console.error('oops', err));

example

Upload a NodeFile from a JSON object

import { NodeFile } from '@graphistry/node-api';
const nodesFile = new NodeFile({'n': ['a', 'b', 'c']});
await nodesFile.upload(client);
console.log(`NodeFile uploaded as ID ${nodesFile.fileID}`);

example

Upload a NodeFile from an Apache Arrow Table

import { tableFromArrays, tableToIPC } from 'apache-arrow';
import { NodeFile } from '@graphistry/node-api';
const json = {'n': ['a', 'b', 'c']};
const arr = tableFromArrays(json);
const uint8Buf = tableToIPC(arr);
const nodesFile = new NodeFile(uint8Buf, 'arrow');
await nodesFile.upload(client);
console.log(`NodeFile uploaded as ID ${nodesFile.fileID}`);

example

Create a File by ID (e.g., previously uploaded) for use with Datasets

import { EdgeFile, Dataset } from '@graphistry/node-api';
const edgesFile = new EdgeFile('my_file_id');
await (new Dataset(bindings, edgesFile)).upload(client);
console.log(`Dataset uploaded as ID ${dataset.datasetID}`);

Hierarchy

Index

Constructors

  • new File(type: FileType, data?: any, fileFormat?: string, name?: string, createOpts?: {}, uploadUrlOpts?: string): File

Methods

  • createFile(client: ClientType, force?: boolean): Promise<any>
  • See examples at top of file

    Helper function to create the file on the server but not yet upload its data

    By default, this will skip recreating files that have already been created.

    Parameters

    • client: ClientType

      Client object to use for uploading

    • Optional force: boolean

      If true, will force creation of a new ID even if file has already been uploaded

    Returns Promise<any>

  • setData(data: any): void
  • See examples at top of file

    Populate data for later uploading if it wasn't set during construction

    Cannot run this function if the file has already been uploaded

    Overwrites any existing data

    Parameters

    • data: any

      Data to use for uploading

    Returns void

  • upload(client: ClientType, force?: boolean): Promise<File>
  • See examples at top of file

    Upload curent File object to the server

    By default, this will skip reuploading files that have already been uploaded.

    Parameters

    • client: ClientType

      Client object to use for uploading

    • Optional force: boolean

      If true, will force upload even if file has already been uploaded

    Returns Promise<File>

    Promise that resolves to the uploaded File object when it completes uploading

  • uploadData(client: ClientType, force?: boolean): Promise<any>
  • See examples at top of file

    Helper function to upload the data to the server

    By default, this will skip reuploading data that has already been uploaded.

    Parameters

    • client: ClientType

      Client object to use for uploading

    • Optional force: boolean

      If true, will force upload even if file has already been uploaded

    Returns Promise<any>

Properties

createOpts: Record<string, any>
fileFormat: string
name: string
type: FileType
uploadUrlOpts: string
_data: any
_fileCreateResponse: any
_fileCreated: any
_fileID?: any
_fileUploadResponse: any
_fileUploaded: any
_fileValidated: any
fillMetadata: any

Accessors

  • get data(): any
  • get fileCreateResponse(): any
  • get fileCreated(): boolean
  • get fileID(): undefined | string
  • get fileUploadResponse(): any
  • get fileUploaded(): any
  • get fileValidated(): any