Blob Attributes

Blob attributes are able to store much more data than any other attribute data type. Blobs are reported as base64 encoded values.

Blob Diagram

While creating, you may specify a Content-Type to save the data as the proper file type.

Common use cases for Blobs are storing image data or snapshots of high frequency data.

What is a Blob?

A Blob is a Binary Large Object which is a collection of binary data stored as a single entity in a database. Blobs are images, CSVs, and binary data, but they can hold data of any type.

Images

You can use Blobs to store images.

Blob On Image Dashboard

You may report your images as base64 encoded strings. For example state report:

{
  "data" : {
    "image": "/9j/4AAQSkZJRgABAQEAYABgAAD//gA7Q1JFQVRPUjogZ2===",
  },
  "time": <Optional Timestamp>,
  "flowVersion": <Optional Workflow Version Name>
}

While storing Blobs that represent images, you may use them in the Image Block or the Custom HTML Block within a dashboard. For example, this allows for your dashboard to display the most recent image of a device.

High Frequency Data

“High frequency data” can be defined as anything that is reporting state many many times per second. For example, binary values or even sizable CSV data:

{
  "data" : {
    "csv": "/9j/4AAQSkZJRgABAQEAYABgAAD//gA7Q1JFQVRPUjogZ2===",
  },
  "time": <Optional Timestamp>,
  "flowVersion": <Optional Workflow Version Name>
}

Blobs are a great way to store a snapshot of the high-frequency data. While you cannot aggregate over data that exists inside of the Blob, you may use a snapshot of the high-frequency data:

Aggregations are allowed using the other attribute data types. It is common to store the aggregated values with the high frequency snapshot. Like so:

{
  "data" : {
    "csv": "/9j/4AAQSkZJRgABAQEAYABgAAD//gA7Q1JFQVRPUjogZ2===",
    "max": 100,
    "average": 34,
  },
  "time": <Optional Timestamp>,
  "flowVersion": <Optional Workflow Version Name>
}

Blob Usage

Depending on what resource you are using in Losant you can either get the original base64 data or a Signed URL. This is because the data can be so large it can be difficult to get all the data into a payload, thus you may get back a Signed URL where you have the option to distribute or download in the browser or workflow.

Blob Attribute

Signed URLs

A Signed URL is a URL with a signature and an expiration date. It allows anyone who has a copy of the link to access the data until the URL expires.

The following is an example Signed URL payload of a device state from the Data Gauge Query:

Signed Links

{
  "data" : {
    "result": {
      "value": "https://storage.googleapis.com/losant-blob/5ea05725a2efcc00077a81d1/5ea057fc848d990006aceae9/blob/1588017908000-44221a392685cefc91513cfbdea1fbd8.jpeg?GoogleAccessId=data-export%40structure-1104.iam.gserviceaccount.com&Expires=1588104310&Signature=X%2FiIWMGwykuqmG9d57Kb%2Fz8s%2BFvnH4Xuq58%2BR2ekrC5CpBIWhrUYOBK4LrUjDuBNGn2IdsuhcKKJ4iPAO3PCEaj6avmwbn9TsePkwhhmmJiJeYHbe3IGMG3XdQUDauffIqUtaOpjP7oE8ddXAhJNm%2F43ekDIsiiqJOSt%2F3Fc94GBeAMaich6w40w%2FrAWlP6rlkAODQQxOftU8JmZesV65sR3g4hClfYntodFpAF9Ks4sCpjorhH2M79ceTVvnf4DtS00zzpII7iBKmbYU4d7fxqoUwlPqOApmnftaLoYgL%2Fnkp8dkKYq%2FDmEVfmg0uYw%3D%3D&response-content-disposition=attachment%3B%20filename%3D%221588017908000-44221a392685cefc91513cfbdea1fbd8.jpeg%22",
      "time": <Timestamp of the reported state>
    }
  },
  "time": <Optional Timestamp>,
  "flowVersion": <Optional Workflow Version Name>
}

For a Data Gauge Query, you get a Signed URL because the data has already been saved and you can download the file using the HTTP node on the workflow.

The following are resources where you may utilize the Signed URL:

Certain areas throughout the platform will always display a Signed URL. For example:

Downloading within a Workflow

Downloading the Blob Data from a Signed URL within a workflow can be accomplished with the HTTP Node.

Downloading Blob Data

The most important field to set is the “Response Encoding Type” to Base64. Then the Blob Data will be within the body of the response.

Signed URL TTL

Signed URLs don’t last forever. The time to live for the Signed URL is configurable on an application level.

Blob TTL

To update the Blob Attribute TTL:

  1. From the Application Menu, navigate to the “Application Info” page.
  2. Select “Blob Attribute TTL”.

The maximum time a Signed URL can live is a week and the shortest is an hour. The default for each application is 24 hours.

Raw Data

Raw data is the original base64 state data that was reported.

The following is an example of a payload on a Device State Trigger:

{
  "data" : {
    "blob_attribute": "/9j/4AAQSkZJRgABAQEAYABgAAD//gA7Q1JFQVRPUjogZ2===",
  },
  "time": <Optional Timestamp>,
  "flowVersion": <Optional Workflow Version Name>
}

The Device State Trigger gets the raw data, allowing you to analyze the data as it is coming into Losant.

The following resources allow you to utilize the raw base64 encoded data:

Reporting Blobs

Blob attributes are reported the same way as other device attribute types. However, Blobs must be reported as base64 encoded values.

Content Types

When configuring a Blob attribute, you must provide a Content Type, which defines the file type of the Blob Data. This also ensure the proper file extension on the Signed URL.

Common content types:

  • PNG image: image/png
  • JPEG image: image/jpeg
  • CSV: text/csv
  • JSON: application/json
  • Binary: application/octet-stream

You can find a more complete list of content types here.

If you are using an unrecognized content type, your file extension will default to .bin.

Converting to Base64

When reporting Blob Data from a workflow you may use the base64Encoded helper to re-encode your UTF8 string to base64:

{{{encodeBase64 working.imageData}}}

Limits

The maximum size for this attribute is 256K.

Was this page helpful?


Still looking for help? You can also search the Losant Forums or submit your question there.