Create

With the Publish() methods you can upload your file on the Aleph network, if you only want to pin an IPFS hash you can refer to the Pin method.

Usage

Import the Store declaration to interact with the Publish function and the Item type to choose your storage location.

import { messages } from 'aleph-sdk-ts';
import { ItemType } from 'aleph-sdk-ts/dist/messages/message';
import { readFileSync } from "fs";

// Or used optimized import

import { Publish as publishStore } from 'aleph-sdk-ts/dist/messages/store';

Then call the publishStore function, with the required parameters as follow:

(async() => {
    const fileContent = readFileSync("./src/testFile.txt");

    const res = await publishStore({
        account: account,
        channel: 'TEST',
        fileObject: fileContent,
    })
})()

Parameters

ParameterDescription

account - required Account

Account to use for signing.

channel - required string

Channel of the message. Ideally, an application would decide and use one channel.

fileObject - required file or blob

The file you want to store.

storageEngine - optional ItemType

Storage engine to use, either Aleph storage or IPFS.

Possible values: ItemType.storage or ItemType.ipfs

APIServer - optional string

The API server endpoint used to carry the request to Aleph's network. default: 'https://api2.aleph.im'

Return

This will return an object like this:

{
  signature: '0x466e7691dcd7fcb74fae2e1bc74e6b30041b229798623918de41240f44a0a01f74b0d643396426a262132052b079c16fdb6c805e7abfb258efd185a74d0272191c',
  chain: 'ETH',
  sender: '0xCFE1FCc630793A1107dbd6BE592044Ba7a279bCd',
  type: 'STORE',
  channel: 'TEST',
  confirmed: false,
  time: 1670241587.703,
  size: 0,
  item_type: 'inline',
  item_content: '{"address":"0xCFE1FCc630793A1107dbd6BE592044Ba7a279bCd","item_type":"storage","item_hash":"d8e5318e012482c62c7367725211455c77eacd107450b0f40030aa0a8422e412","time":1670241587.703}',
  item_hash: 'f7b9eda3a048bfd821c1c5cd0b231826600eb68fe3e5a92a65e0095ea80c3273',
  content: {
    address: '0xCFE1FCc630793A1107dbd6BE592044Ba7a279bCd',
    item_type: 'storage',
    item_hash: 'd8e5318e012482c62c7367725211455c77eacd107450b0f40030aa0a8422e412',
    time: 1670241587.703
  }
}

Look at this message on Aleph Explorer! Download the file here.

Retrieve file via direct url

In the response, item_hash inside the content filed can be used to retrieve the stored file via a direct URL as follow:

Via storageEngine.storage:

https://<API SERVER URL>/api/v0/storage/raw/<File Item Hash Here>

Via storageEngine.ipfs:

Or at the IPFS URL: https://ipfs.io/ipfs/<File Item Hash Here>

Last updated