Bloqifi RESTful API documentation
  • The Next Generation Web³
  • Quick Start
  • Blog
  • Reference
    • API Reference
      • Authentication
      • Bloq
      • Payment
      • Transaction
      • Rates
    • Retrieval
      • Transaction ID
      • Web
      • Blob
      • Chunk
  • Stripe Metered Billing
    • API Reference
      • Subscribe
      • Check Usage
Powered by GitBook
On this page
  • Creating a new bloq
  • Create bloq
  • Create a new folder
  • Create new folder
  • Merge chunks for created bloq
  • Merge chunks

Was this helpful?

  1. Reference
  2. API Reference

Bloq

Making an authenticated call to the bloq endpoint

Creating a new bloq

We use chunking which is useful in big size files uploading. In chunk uploading, you can configure how much size each chunk should upload to the server.

Create bloq

POST https://api.bloqifi.com/v0/bloq

Creates a new bloq

Headers

Name
Type
Description

Authorization*

String

Bearer ${accessToken}

Content-Length

String

Content length

blockchain*

String

Bloqcoin, Dogecoin, Bitcoin, IPFS

Cache-Control

String

no-cache

Content-Type*

String

application/json

folder

String

${folderId}

Request Body

Name
Type
Description

multipart/form-data**

String

Any appropriate content

{
    message: 'Original file name'
}
{
    message: 'Unprocessable Entity'
}

The Chunked Upload API provides a way to reliably upload large files to Bloqifi by chunking them into a sequence of parts that can be uploaded individually. By using this API the application uploads a file in part, allowing it to recover from a failed request more reliably.

export const deployToBloqifi = async ({name, description, blockchain, content, token}) => {

const formHash = {
  'dzuuid': 'Random-' + Date.now(),
  'dzchunkindex': '0',
  'dztotalfilesize': Buffer.byteLength(content),
  'dzchunksize': 1000000,
  'dztotalchunkcount': '1',
  'dzchunkbyteoffset': '0'
}

const boundary = formHash.dzuuid;
let body = '';

for (let key in formHash) {
  body += `-----------------------------${boundary}\r\n`;
  body += `Content-Disposition: form-data; name="${key}"\r\n\r\n`;
  body += `${formHash[key]}\r\n`;
}

body += `-----------------------------${boundary}\r\n`;
body += `Content-Disposition: form-data; name="file"; filename="${name}"\r\n`;
body += `Content-Type: application/octet-stream\r\n\r\n${content}\r\n`;
body += `-----------------------------${boundary}--`;

const rawResponse = await fetch('https://api.bloqifi.com/v0/bloq', {
  method: 'POST',
  headers: {
    'Content-Type': 'multipart/form-data; boundary=---------------------------' + boundary,    
    'Authorization': 'Bearer ' + token,
    'blockchain': blockchain,
    'Cache-Control': 'no-cache',
    'Content-Length': Buffer.byteLength(content)
  },
  body: body
});
}

Good to know: By using this API the application uploads a file in part, allowing it to recover from a failed request more reliably. It means an application only needs to retry the upload of a single part instead of the entire file.

An additional benefit of chunked uploads is that parts can be uploaded in parallel, allowing for a potential performance improvement.

Create a new folder

You'll need a folder ID to merge chunks from a new bloq.

Create new folder

PATCH https://api.bloqifi.com/v0/bloq

Creates a new folder, or receive current folder id

Headers

Name
Type
Description

Content-Type

String

application/json

Authorization*

String

Bearer ${accessToken}

Request Body

Name
Type
Description

name*

String

Name of folder

blockchain*

String

Bloqcoin, Dogecoin, Bitcoin, IPFS

{
    id: new ObjectId
}
{
    message: 'err'
}
{
    id: ObjectId
}
const rawResponse = await fetch('https://api.bloqifi.com/v0/bloq', {
  method: 'PATCH',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': `Bearer ${token}`
  },
  body: JSON.stringify({
    name: 'New Folder',
    blockchain: 'Bloqcoin'
  })
});

const json = await rawResponse.json();

// 201 Created
if (rawResponse.status === 201) {

  // grep folder id
  json.id
}

Merge chunks for created bloq

The merge and combine of multiple chunks in the created bloq could take a while for larger files, however not longer then any predefined timeouts.

Merge chunks

PUT https://api.bloqifi.com/v0/bloq

Headers

Name
Type
Description

Authorization*

String

Bearer ${accessToken}

Content-Type*

String

application/json

Request Body

Name
Type
Description

originalname*

String

Name of file

folder*

String

${folderId}

dzuuid*

String

${dzuuid}

dztotalchunkcount*

String

${dztotalchunkcount}

dztotalfilesize*

String

${dztotalfilesize}

blockchain*

String

Bloqcoin, Dogecoin, Bitcoin, IPFS

{
    message: 'Merged successfully..',
    id: new ObjectId,
    hexSize: 100
}
{
    message: 'Unprocessable Entity'
}
const rawResponse = await fetch('https://api.bloqifi.com/v0/bloq', {
  method: 'PUT',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': `Bearer ${token}`
  },
  body: JSON.stringify({
    dzuuid: ${dzuuid},
    originalname: `Name of file`,
    dztotalfilesize: ${dztotalfilesize},
    dztotalchunkcount: ${dztotalchunkcount},
    blockchain: 'Bloqcoin',
    folder: ${ObjectId}
  })
});

const json = await rawResponse.json();

// 201 Created
if (rawResponse.status === 201) {

  // merge complete
}

In some cases, creating the parts might take a long time and the API will return a 202 Accepted status code instead.

Good to know: If any of the blockchains is used (Bloqcoin, Dogecoin, Bitcoin) payment is required and you'll need the json.id to complete the next step.

PreviousAuthenticationNextPayment

Last updated 2 years ago

Was this helpful?