Storage

The Fleek Platform SDK provides a storage service allowing you to store your files in a decentralized manner. Our service supports IPFS as our main storage protocol, complemented by Arweave and Filecoin as a backup layer. This approach ensures a high-performing and highly available service. Filecoin acts as the default backup layer, but modifications can be implemented in the storage settings.

Methods

Here is a list of the available methods for the Fleek Platform SDK Storage Service:

Method                      Description
-----------------------------------------------------------------------------------------------------------------
uploadFile                  Upload a file to IPFS
uploadDirectory             Upload a directory to IPFS
uploadVirtualDirectory      Upload a virtual directory to IPFS
get                         Get a file by CID
getByFilename               Get a file by Filename
list                        List files
delete                      Delete a file by CID

uploadFile

The uploadFile is an asynchronous function designed to upload a file to Fleek Platform Storage Service.

Function Signature

async ({ file, onUploadProgress }: UploadRawFileArgs): Promise<UploadPinResponse>

Parameters

The file parameter is an instance of IpfsFile, a type that represents the file to be uploaded.

type UploadRawFileArgs = {
  file: FileLike;
  // A callback or handler for the upload progress
  onUploadProgress?: (uploadProgress: UploadProgress) => void;
};
type UploadProgress = {
  loadedSize: number;
  totalSize: number;
};
type FileLike = {
  name: string;
  stream: () => ReadableStream;
};

Returns

type UploadPinResponse = {
  pin: {
    cid: string;
    size: number;
  };
  duplicate: boolean;
};

Usage Example

// The Fleek SDK should be authenticated
// with a valid Project ID
const result = await fleekSdk.storage().uploadFile({
  file,
  onUploadProgress,
});

const onUploadProgress = ({ loadedSize, totalSize }: UploadProgress) => {
  if (loadedSize > 0) {
    const currentTime = DateTime.now();
    const elapsedMillis = currentTime.diff(startedTime).as('milliseconds');

    const bytesPerSecond = loadedSize / (elapsedMillis / 1000);
    const remainingBytes = totalSize - loadedSize;
    const remainingSeconds = remainingBytes / bytesPerSecond;
    const remainingTime = remainingSeconds * 1000;

    // Does something with remainingTime
  }
};

list

The list is an asynchronous function designed to get a list of files uploaded to a projects storage.

Function Signature

async (): Promise<StoragePin[]>

Parameters

Not required.

Returns

type StoragePin = {
  cid?: string;
  size?: number;
  filename?: string;
  filecoinDealIds?: string;
  arweavePin?: ArweavePin;
  arweaveId?: string;
};
type ArweavePin = {
  cid: string;
  bundlrId: string;
  price: runtime.Decimal;
  createdAt: Date;
};

Usage Example

// The Fleek SDK should be authenticated
// with a valid Project ID
const result = await fleekSdk.storage().list();

Delete

The delete is an asynchronous function designed to delete a storage file by it’s CID.

Function Signature

async ({ cid }: DeletePinArgs)

Parameters

type DeletePinArgs = {
  cid: string;
};

Returns

type Response = {
  status: number;
  // TODO: provide type
  body: Record<string, unknown>;
};

Usage Example

// The Fleek SDK should be authenticated
// with a valid Project ID
const result = await fleekSdk.storage().list();

uploadDirectory

Upload a directory to Fleek Platform Storage IPFS.

Function Signature

async ({ path, options, onUploadProgress }: UploadDirectoryArgs): Promise<UploadPinResponse>

Parameters

type UploadDirectoryArgs = {
  path: string;
  options?: UploadDirectoryOptions;
  onUploadProgress?: (uploadProgress: UploadProgress) => void;
};

Returns

type UploadPinResponse = {
  pin: {
    cid: string;
    size: number;
  };
  duplicate: boolean;
};

uploadVirtualDirectory

Upload a virtual directory to Fleek Platform Storage IPFS.

Function Signature

async ({
    files,
    directoryName,
    onUploadProgress,
  }: UploadVirtualDirectoryArgs): Promise<UploadPinResponse>

Parameters

type UploadVirtualDirectoryArgs = {
  files: FileLike[];
  directoryName: string;
  onUploadProgress?: (uploadProgress: UploadProgress) => void;
};
type FileLike = {
  name: string;
  stream: () => ReadableStream;
};

Returns

type UploadPinResponse = {
  pin: {
    cid: string;
    size: number;
  };
  duplicate: boolean;
};