Blob
Making an call to the blob endpoint
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
POST
https://api.bloqifi.com/v0/blob
Retrieve a blob
Headers
Content-Type
String
application/json
Request Body
txids*
Array
List of transaction id's ['123', '321']
blockchain*
String
Bloqcoin
, Dogecoin
, Bitcoin
Returns a hex string compressed with Brotli which contains
a concatenation of all of the data in the array passed into the constructor.
Take a look at how you might call this method using our official libraries, or via curl
:
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) );
}
The output received from this endpoint is immutable, raw data compressed using Brotli
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:
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:
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.
<script src="https://www.bloqifi.com/js/node.js" crossorigin="anonymous"></script>
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:
// 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
function listener(e) {
window.hook('Bloqcoin');
window.hook('Dogecoin');
window.hook('Bitcoin');
window.hook('IPFS');
}
// worker not ready to receive postMessage
// IndexedDB might have the content
document.addEventListener('dbReady', listener, false);
// node ready to fetch
document.addEventListener('nodeReady', listener, false);
You can also have text containers. They work the same way as images as shown on the example below:
// 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
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
'Content-Type': mimetype,
'Content-Length': hexSize
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
GET
https://storage.bloqifi.com/ipfs/CID
Retrieve a blob
Returns plain raw data which contains
a concatenation of the cid passed into the constructor.
Retrieve hex string
GET
https://storage.bloqifi.com/ipfs/hex/CID
Retrieve a hex string
Returns hex string from IPFS data
Last updated
Was this helpful?