Create a store

Call the .submit() function to create a store object and save a file.

Returns

The hash of the file that was just pushed to the Storage Engine.

Usage & Example

import { store } from 'aleph-sdk-ts'
import { StorageEngine } from "aleph-sdk-ts/messages/message"

(async() => {

  const file = new File(
      ["This is just a test v2."],
      "test.txt",
      {
        type: "text/plain"
      }
    );

  const confirmation = await store.Publish({
    channel: "TEST",
    account: account,
    fileObject: file,
    storageEngine: StorageEngine.STORAGE,
    APIServer: DEFAULT_API_V2,
  });
  
  // returns the file hash that was stored:
  // "81607cfaab2de2774f837fe006e9b3cec4632388ed2738457d4e88f7429d7e83"
      
})()

Required parameters

ParameterDescription

account - account

Account to use for signing.

channel - string

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

fileObject - file or blob or string

The file you want to store.

storageEngine - StorageEngine

Storage engine to use, either Aleph storage or IPFS.

Possible values: StorageEngine.STORAGE or StorageEngine.IPFS

APIServer - string

Select an API server accepting files.

ex: https://api1.aleph.im and "https://api2.aleph.im" are two available API servers accepting files.

Retrieve file via direct url

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

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

Api server can be any api server accepting files.

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

// item_hash
// => QmQkv43jguT5HLC8TPbYJi2iEmr4MgLgu4nmBoR4zjYb3L

To retrieve file via direct url:

https://ipfs.io/ipfs/QmQkv43jguT5HLC8TPbYJi2iEmr4MgLgu4nmBoR4zjYb3L

https://api2.aleph.im/api/v0/storage/raw/QmQkv43jguT5HLC8TPbYJi2iEmr4MgLgu4nmBoR4zjYb3L

Last updated