Uploading an asset via API

:wave:, Builders

I’m working on an image/document capture app that pushes uploads to another service via API.

Because the external service requires files to be base64 encoded, I tried running the BASE64_ENCODE() Airscript function on my asset (see screenshot) but it doesn’t seem to be working. What should I try next?

3 Likes

Hey Ian! So in Airkit, we have what we call the Asset Data Type which is a referer to your file with some information such as the ID or downloadUrl but doesn’t necessarily include the contents of your file.

For example if someone were to upload a document to an Airkit App, you’d get an object that looks something like this:

{
  "size": 13598,
  "thumbnailUrl": "https://assets.airkit.com",
  "validationErrors": null,
  "deletedTime": null,
  "downloadUrl": "https://assets.airkit.com/",
  "displayName": "image (17).png",
  "organizationId": "",
  "assetKey": "",
  "expiration": 3600000,
  "state": "ACTIVE",
  "visibility": "GLOBAL",
  "scope": "SESSION",
  "region": "us-west-2",
  "createdTime": "2022-01-05T23:39:14.180Z",
  "modifiedTime": "2022-01-05T23:39:16.122Z",
  "version": 0,
  "type": "image/png",
  "id": "",
  "description": null,
  "extraInfo": null
}

I believe from here in your data flow, you can use the ASSET_TO_URI function to change this to an asset primitive. And then use the Download Encoded Asset data operation to get a BASE64 encoded file.

2 Likes

Download encoded asset, that was it!

1 Like

is it possible to download the asset using a download button when a user clicked on it?
what operations need to perform for that?

If you have a Detailed Asset, it comes out of the box with the downloadUrl attribute. You can use this to set the destination (Href) for a Hyperlink Web Control. If you want the Hyperlink to look more like a Button, there’s a Variant for that.

1 Like