Fetch

Usage

In order to retrieve a file content from a Store message, you can use the Get() function provided by the Store object given in aleph-sdk-ts import.

import { messages } from 'aleph-sdk-ts';

or

import { Get as getStore } from 'aleph-sdk-ts/dist/messages/store';
import { Get as getStore } from 'aleph-sdk-ts/dist/messages/store';


(async() => {
    await getStore({
        fileHash: file_hash
    })
})()

Parameters

ParameterDescription

fileHash - required string

content.item_hash generated from creating the file on the api server

APIServer - optional string

API server accepting files. Default: "https://api2.aleph.im"

Return

The Get() method returns the content of the file as an ArrayBuffer. It can be turned into a string using the following:

import { Get as getStore } from 'aleph-sdk-ts/dist/messages/store';

(async() => {
    const res = await getStore({
        fileHash: 'QmQkv43jguT5HLC8TPbYJi2iEmr4MgLgu4nmBoR4zjYb3L'
      })

    // Buffer can be converted back to a string like so:
    new TextDecoder().decode(res)
    // => 'This is just a test.'
})()

Retrieve from an API server

If the file is stored on aleph storage:

// https://<FILE API_SERVER>/api/v0/storage/raw/<FILE ITEM HASH HERE>

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

If the file is stored on IPFS compatible server, the file is also available on:

// https://ipfs.io/ipfs/<FILE ITEM HASH HERE>

https://ipfs.io/ipfs/QmQkv43jguT5HLC8TPbYJi2iEmr4MgLgu4nmBoR4zjYb3L

Last updated