Human Protocol SDK
v4.0.0
v4.0.0
  • Typescript SDK
    • Encryption
      • Encryption
      • EncryptionUtils
    • Escrow
      • EscrowClient
      • EscrowUtils
    • KVStore
      • KVStoreClient
      • KVStoreUtils
    • Staking
      • StakingClient
    • Operator
      • OperatorUtils
    • Storage
      • StorageClient
    • Statistics
      • StatisticsClient
    • Transaction
      • TransactionUtils
  • Python SDK
    • agreement
      • bootstrap
      • measures
      • utils
    • encryption
      • encryption
      • legacy_encryption
      • encryption_utils
    • escrow
      • escrow_client
      • escrow_utils
    • kvstore
      • kvstore_client
      • kvstore_utils
    • staking
      • staking_client
      • staking_utils
    • operator
      • operator_utils
    • statistics
      • statistics_client
    • storage
      • storage_client
      • storage_utils
    • transaction
      • transaction_utils
    • constants
    • filter
    • utils
  • CHANGELOG
Powered by GitBook
On this page
  • Class: StorageClient
  • Deprecated
  • Introduction
  • Installation
  • Code example
  • Constructors
  • Methods
  1. Typescript SDK
  2. Storage

StorageClient

Last updated 3 months ago


/ / StorageClient

Class: StorageClient

Deprecated

StorageClient is deprecated. Use Minio.Client directly.

Introduction

This client enables interacting with S3 cloud storage services like Amazon S3 Bucket, Google Cloud Storage, and others.

The instance creation of StorageClient should be made using its constructor:

constructor(params: StorageParams, credentials?: StorageCredentials)

If credentials are not provided, it uses anonymous access to the bucket for downloading files.

Installation

npm

npm install @human-protocol/sdk

yarn

yarn install @human-protocol/sdk

Code example

import { StorageClient, StorageCredentials, StorageParams } from '@human-protocol/sdk';

const credentials: StorageCredentials = {
  accessKey: 'ACCESS_KEY',
  secretKey: 'SECRET_KEY',
};
const params: StorageParams = {
  endPoint: 'http://localhost',
  port: 9000,
  useSSL: false,
  region: 'us-east-1'
};

const storageClient = new StorageClient(params, credentials);

Constructors

new StorageClient()

Storage client constructor

Parameters

params

Cloud storage params

credentials?

Optional. Cloud storage access data. If credentials are not provided - use anonymous access to the bucket

Returns

Defined in

Methods

bucketExists()

bucketExists(bucket): Promise<boolean>

This function checks if a bucket exists.

Parameters

bucket

string

Bucket name.

Returns

Promise<boolean>

Returns true if exists, false if it doesn't.

Code example

import { StorageClient, StorageCredentials, StorageParams } from '@human-protocol/sdk';

const credentials: StorageCredentials = {
  accessKey: 'ACCESS_KEY',
  secretKey: 'SECRET_KEY',
};
const params: StorageParams = {
  endPoint: 'http://localhost',
  port: 9000,
  useSSL: false,
  region: 'us-east-1'
};

const storageClient = new StorageClient(params, credentials);
const exists = await storageClient.bucketExists('bucket-name');

Defined in


downloadFiles()

downloadFiles(keys, bucket): Promise<any[]>

This function downloads files from a bucket.

Parameters

keys

string[]

Array of filenames to download.

bucket

string

Bucket name.

Returns

Promise<any[]>

Returns an array of JSON files downloaded and parsed into objects.

Code example

import { StorageClient, StorageCredentials, StorageParams } from '@human-protocol/sdk';

const params: StorageParams = {
  endPoint: 'http://localhost',
  port: 9000,
  useSSL: false,
  region: 'us-east-1'
};

const storageClient = new StorageClient(params);

const keys = ['file1.json', 'file2.json'];
const files = await storageClient.downloadFiles(keys, 'bucket-name');

Defined in


listObjects()

listObjects(bucket): Promise<string[]>

This function lists all file names contained in the bucket.

Parameters

bucket

string

Bucket name.

Returns

Promise<string[]>

Returns the list of file names contained in the bucket.

Code example

import { StorageClient, StorageCredentials, StorageParams } from '@human-protocol/sdk';

const credentials: StorageCredentials = {
  accessKey: 'ACCESS_KEY',
  secretKey: 'SECRET_KEY',
};
const params: StorageParams = {
  endPoint: 'http://localhost',
  port: 9000,
  useSSL: false,
  region: 'us-east-1'
};

const storageClient = new StorageClient(params, credentials);
const fileNames = await storageClient.listObjects('bucket-name');

Defined in


uploadFiles()

This function uploads files to a bucket.

Parameters

files

any[]

Array of objects to upload serialized into JSON.

bucket

string

Bucket name.

Returns

Returns an array of uploaded file metadata.

Code example

import { StorageClient, StorageCredentials, StorageParams } from '@human-protocol/sdk';

const credentials: StorageCredentials = {
  accessKey: 'ACCESS_KEY',
  secretKey: 'SECRET_KEY',
};
const params: StorageParams = {
  endPoint: 'http://localhost',
  port: 9000,
  useSSL: false,
  region: 'us-east-1'
};

const storageClient = new StorageClient(params, credentials);
const file1 = { name: 'file1', description: 'description of file1' };
const file2 = { name: 'file2', description: 'description of file2' };
const files = [file1, file2];
const uploadedFiles = await storageClient.uploadFiles(files, 'bucket-name');

Defined in


downloadFileFromUrl()

static downloadFileFromUrl(url): Promise<any>

This function downloads files from a URL.

Parameters

url

string

URL of the file to download.

Returns

Promise<any>

Returns the JSON file downloaded and parsed into an object.

Code example

import { StorageClient } from '@human-protocol/sdk';

const file = await StorageClient.downloadFileFromUrl('http://localhost/file.json');

Defined in

new StorageClient(params, credentials?):

uploadFiles(files, bucket): Promise<[]>

Promise<[]>

@human-protocol/sdk
@human-protocol/sdk
storage
StorageClient
StorageParams
StorageCredentials
StorageClient
storage.ts:73
storage.ts:262
storage.ts:112
storage.ts:292
UploadFile
UploadFile
storage.ts:198
storage.ts:146