> For the complete documentation index, see [llms.txt](https://docs.bloqifi.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.bloqifi.com/reference/retrieval/blob.md).

# Blob

## Fetch blob from blockchain

The Blob object represents a blob, which is a file-like object of immutable, raw data; they can be read as text or binary data, or converted into a `ReadableStream` so its methods can be used for processing the data.

## Retrieve blob

<mark style="color:green;">`POST`</mark> `https://api.bloqifi.com/v0/blob`

Retrieve a blob

#### Headers

| Name         | Type   | Description      |
| ------------ | ------ | ---------------- |
| Content-Type | String | application/json |

#### Request Body

| Name                                         | Type   | Description                                |
| -------------------------------------------- | ------ | ------------------------------------------ |
| txids<mark style="color:red;">\*</mark>      | Array  | List of transaction id's \[`'123', '321']` |
| blockchain<mark style="color:red;">\*</mark> | String | `Bloqcoin`, `Dogecoin`, `Bitcoin`          |

{% tabs %}
{% tab title="200: OK " %}

```
Returns a hex string compressed with Brotli which contains
a concatenation of all of the data in the array passed into the constructor.
```

{% endtab %}

{% tab title="404: Not Found " %}

{% endtab %}
{% endtabs %}

Take a look at how you might call this method using our official libraries, or via `curl`:

{% tabs %}
{% tab title="JavaScript" %}

```javascript
const rawResponse = await fetch('https://api.bloqifi.com/v0/blob', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    blockchain: 'Bloqcoin',
    txids: ['123', '321']
  })
});

const result = await rawResponse.text();

if (rawResponse.status === 200) {

  const fromHexString = hexString => Uint8Array.from(hexString.match(/.{1,2}/g).map(byte => parseInt(byte, 16)));
  const compressedData = fromHexString(result);
  
  // data contains the raw brotli compressed data
  
  const decompressedData = brotli.decompress(compressedData);
  
  const textDecoder = new TextDecoder();
  
  console.log( textDecoder.decode(decompressedData) );
}
```

{% endtab %}

{% tab title="curl" %}

```
curl -X POST https://api.bloqifi.com/v0/blob \
-H "Content-Type: application/json" \
-d '{"blockchain": "Bloqcoin", "txids": ["123", "321"]}' 
```

{% endtab %}
{% endtabs %}

The output received from this endpoint is immutable, raw data compressed using `Brotli`

{% hint style="info" %}
**Good to know:** Notice that the Blockchain string used is capitalized, this is required.

In the example we will be using `Bloqcoin`, other supported blockchains are:

`Dogecoin`, `Bitcoin`
{% endhint %}

`Brotli` is a lossless data compression algorithm developed by Google. It uses a combination of the general-purpose LZ77 lossless compression algorithm, Huffman coding and 2nd order context modelling.

Install using NPM.

```
npm install brotli-wasm
```

A reliable compressor and de-compressor for Brotli, supporting node & browsers via wasm

**In node.js:**

```javascript
const * as brotli = require('brotli-wasm');

const compressedData = brotli.compress(Buffer.from('some input'));
const decompressedData = brotli.decompress(compressedData);

console.log(Buffer.from(decompressedData).toString('utf8')); // Prints 'some input'
```

**In browsers:**

```javascript
import brotliPromise from 'brotli-wasm'; // Import the default export

const brotli = await brotliPromise; // Import is async in browsers due to wasm requirements!

const compressedData = brotli.compress(Buffer.from('some input'));
const decompressedData = brotli.decompress(compressedData);

console.log(Buffer.from(decompressedData).toString('utf8')); // Prints 'some input'
```

## JavaScript Node

To construct a Blob from transaction ids, you can also use Bloqifi JavaScript Node:

`Bloqcoin` very fast. `Dogecoin` much reliable, Wow. // One line of code is all it takes.

```html
<script src="https://www.bloqifi.com/js/node.js" crossorigin="anonymous"></script>
```

{% hint style="info" %}
**Good to know:** The `integrity` and `crossorigin` attributes are used for [Subresource Integrity (SRI) checking](https://www.w3.org/TR/SRI/). This allows browsers to ensure that resources hosted on third-party servers have not been tampered with. Use of SRI is recommended as a best-practice, whenever libraries are loaded from a third-party source. Read more at [srihash.org](https://www.srihash.org/)
{% endhint %}

One line of code is all it takes to use images, text and more on your own website.

Include the Bloqifi JavaScript node on your site, and define your image tags:

```html
// Get data as Blob

<img class="Bloqcoin" type="blob" data-src="txids" data-mimetype="image/png" style="visibility:hidden;" />

// Retrieve data Chunked

<img class="Bloqcoin" type="chunk" data-src="txids" data-mimetype="image/png" style="visibility:hidden;" />

// Or utilize Dogecoin as blockchain

<img class="Dogecoin" type="blob" data-src="txids" data-mimetype="image/png" style="visibility:hidden;" />
<img class="Dogecoin" type="chunk" data-src="txids" data-mimetype="image/png" style="visibility:hidden;" />

// Even IPFS

<img class="IPFS" type="blob" data-src="hash" data-mimetype="image/png" style="visibility:hidden;" />
<img class="IPFS" type="chunk" data-src="hash" data-mimetype="image/png" style="visibility:hidden;" />
```

Join all your `bloq` transaction ids (txid) as one comma separated string, and add it as `data-src` on an image tag to show the image.

If you add images dynamically, you can hook up to the "ready" event

<pre class="language-javascript"><code class="lang-javascript">function listener(e) {
  window.hook('Bloqcoin');
  window.hook('Dogecoin');
  window.hook('Bitcoin');
  window.hook('IPFS');
}
<strong>
</strong><strong>// worker not ready to receive postMessage
</strong>// IndexedDB might have the content
document.addEventListener('dbReady', listener, false);

// node ready to fetch
document.addEventListener('nodeReady', listener, false);
</code></pre>

You can also have text containers. They work the same way as images as shown on the example below:

```html
// Get data as Blob

<pre class="Bloqcoin" type="blob" data-src="txids" data-mimetype="text/plain"></pre>

// Retrieve data Chunked

<pre class="Bloqcoin" type="chunk" data-src="txids" data-mimetype="text/plain"></pre>
```

### HEAD

The HTTP HEAD method requests the headers that would be returned if the HEAD request's URL was instead requested with the HTTP GET method.

For example, if a request might produce a large download, a `HEAD` request could read its [`Content-Length`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Length) header to check the file-size without actually downloading the file.

## Retrieve blob headers

`HEAD` `https://api.bloqifi.com/v0/blob/OBJECTID`

Retrieve a blob's headers

{% tabs %}
{% tab title="200: OK " %}

```
'Content-Type': mimetype,
'Content-Length': hexSize
```

{% endtab %}

{% tab title="404: Not Found " %}

{% endtab %}
{% endtabs %}

### Fetch blob from IPFS

The Blob object represents a blob, which is a file-like object of immutable, raw data; they can be read as text or binary data, or converted into a `ReadableStream` so its methods can be used for processing the data.

## Retrieve blob

<mark style="color:blue;">`GET`</mark> `https://storage.bloqifi.com/ipfs/CID`

Retrieve a blob

{% tabs %}
{% tab title="200: OK " %}

```
Returns plain raw data which contains
a concatenation of the cid passed into the constructor.
```

{% endtab %}
{% endtabs %}

## Retrieve hex string

<mark style="color:blue;">`GET`</mark> `https://storage.bloqifi.com/ipfs/hex/CID`

Retrieve a hex string

{% tabs %}
{% tab title="200: OK " %}

```
Returns hex string from IPFS data
```

{% endtab %}
{% endtabs %}
