# Working with Files and Media

## Application vs. Journey Assets

Airkit handles files and media in two ways on that is part of the application and shared across all users and the other is stored within a particular user's journey.

#### App Assets

App Assets are files & media that are included in the application itself and can be referenced through the Studio when designing an experience. Examples Include:

1. Images in a web experience (PNG, JPG, etc.)
2. Documents to download (PDFs, ZIP etc.)
3. Or other media such as videos (MP4)

These assets need to be included in your [Media Library](../../studio/studio/builder-bar/media-library) and are made available through special URLs that resolve securely to a user through your custom domain and quickly as through the Airkit CDN.

![2021-03-11\_12-30-52\_\_1\_.png](https://2599974655-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIRF6etABDVMr59RdpyGw%2Fuploads%2Fgit-blob-01fb9b612c234f682459bf3c96d9a661ad020cf9%2Fworking-with-files-and-media-v184-0?alt=media).png)

&#x20;

#### Journey Assets

Journey Assets are files that are associated with a specific user's journey within Airkit and can be stored within variables and used within data operations. Some common examples include:

1. [Photos captured](../../web-controls/file-upload-web-control) from a customers mobile device
2. [Files uploaded](https://github.com/airkit/airkit-docs/blob/master/docs/v18-4/media-upload-web-control.md) from a customer
3. [Customer signatures](../../web-controls/signature-control) (PNG)
4. [Generated PDF files](../pdfs/creating-a-pdf) (Form fills, merged PDFs or custom generated)

Because Journey Assets are stored in variables the scope of how long they are available is determined by whether the Journey is active or expired, please see [Journey State](../../concepts/sessions) for more information.

&#x20;

## Working with Assets in Variables

The Asset data type of a variable allows you to work with files and media within a journey using [Airscript](../../working-with-data/working-with-data-overview/airscript-quick-start) and within [Data Flows](../../studio/studio/data-flows).

![](https://2599974655-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIRF6etABDVMr59RdpyGw%2Fuploads%2Fgit-blob-d358339eb3eac913a263c11686faddfec301f02b%2Fworking-with-files-and-media-v184-1.gif?alt=media)

#### Real-World Use Cases

Some examples of when you might use a variable with the [Asset data type](../../variable-data-types/the-asset-data-type) to receive or handle a file

* The [File Upload](../../web-controls/file-upload-web-control) web control to receive photos from a mobile device's camera or photo library
* The [File Upload](../../web-controls/file-upload-web-control) web control to receive files from a mobile device or desktop
* The [Signature Pad](../../web-controls/signature-control) web control to capture a users hand-written e-signature
* Creating a new PDF from an HTML template with user specific values using the [HTML to PDF](../../data-operations/data-operation-overview/the-html-to-pdf-data-operation) Data Operation
* Filling the fields of a form-fillable PDF template with user specific values using [The Fill PDF Form Data Operation](../../data-operations/data-operation-overview/the-fill-pdf-form-data-operation)
* Merging the pages of multiple PDFs together using [The Merge PDF Data Operation](../../data-operations/data-operation-overview/the-merge-pdf-data-operation)
* Generating a flat file from journey or batch data using [The Create File Data Operation](../../data-operations/data-operation-overview/the-create-file-data-operation)
* Combining and compressing multiple files together with [The ZIP File Data Operation](../../data-operations/data-operation-overview/the-zip-file-data-operation)
* Sending files as attachments on emails with [The Send Email Data Operation](../../data-operations/data-operation-overview/the-send-email-data-operation)
* Sending files securely with [The SFTP Data Operation](../../data-operations/data-operation-overview/the-sftp-data-operation)
* Looking up file meta information with [The Fetch Asset Details Data Operation](../../data-operations/data-operation-overview/the-fetch-asset-details-data-operation)
* Deleting one or more Assets with [The Delete Assets Data Operation](../../data-operations/data-operation-overview/the-delete-assets-data-operation)
* Getting a temporary download URL to share with a user with [The Fetch Asset Details Data Operation](../../data-operations/data-operation-overview/the-fetch-asset-details-data-operation)

&#x20;

## Embedding Assets within Your Application

Using [Media Library](../../studio/studio/builder-bar/media-library) you can upload assets to be included and referenced in your application

![](https://2599974655-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIRF6etABDVMr59RdpyGw%2Fuploads%2Fgit-blob-b4392cd3fa0b76b5eb26567c9b53ca0a056af3b9%2Fworking-with-files-and-media-v184-2.gif?alt=media)

&#x20;

Once a file has been uploaded into your Media Library you now have an Asset URI to use to reference the file while building your app.

&#x20;

Inserting Images using the [Image Web Control](../../web-controls/image-web-control)

![](https://2599974655-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIRF6etABDVMr59RdpyGw%2Fuploads%2Fgit-blob-6dcdb45186579a48f60109360efd9b37509f510b%2Fworking-with-files-and-media-v184-3.gif?alt=media)



#### Why Does Airkit Use Special URLs for Assets?

You may notice that the way Airkit refers to files is not a typical URL and isn't able to be retrieved outside of the Airkit platform.  There are two primary reasons for using a specific URI

* **Security** - these Asset URIs can only be accessed in the context of an Airkit operation such as within a journey of a user and are dynamically exchanged for temporary URL
* **Version Control** - we want to make sure that files are tracked across versions of applications easily and caching issues do not arise

#### What are the components of an Asset URI?

`asset://[Access Scope]:[Organization UUID]/[Application UUID]:[File UUID]:[Version Number]`

* **Access Scope**: Global or user specific
* **Organization UUID**: Your Organizations ID
* **Application UUID**: The specific branch of the application that is serving the asset.  This is used for version control so that asset links will still function for journeys that started on an older branch of your application
* **File UUID**: Uniquely represents the file within your application's Media Library
* **Version Number**: An auto-incrementing version number of an asset

&#x20;

## Working with Assets in Data Operations

#### A quick walk through of some Data Operations that work with Assets

&#x20;

There are quite a few Data Operation that either produce files or consume files to perform their actions and all of these functions leverage the Asset variable type to provide or pass around references to the underlying files.  For example:

&#x20;

#### Operations that Create or Consume Files

* [Create File](../../data-operations/data-operation-overview/the-create-file-data-operation) produces any file type and inserts content such as TXT, JSON, XML, CSV, TSV
* [Fill PDF Form](../../data-operations/data-operation-overview/the-fill-pdf-form-data-operation) takes a blank PDF template and merges values into form field to produce a filled PDF
* [HTML to PDF](../../data-operations/data-operation-overview/the-html-to-pdf-data-operation) creates a custom PDF using HTML for layout, styling and allowing full control over data and dynamic content including inserting images, CSS, footers/headers, page breaks and more
* [Merge PDF](../../data-operations/data-operation-overview/the-merge-pdf-data-operation) provides an operation to combine the pages of multiple PDF files into one PDF
* [Create ZIP File](../../data-operations/data-operation-overview/the-zip-file-data-operation) provides an operation to combine and compress multiple files into a single ZIP file

#### Operations that Transmit Files Externally

* [Send Email](../../data-operations/data-operation-overview/the-send-email-data-operation) allows to attach one or more files to an outbound email originated from Airkit
* [SFTP](../../data-operations/data-operation-overview/the-sftp-data-operation) allows sending a file securely over FTP to remote server

#### Operations that Support Asset Operations

* [Fetch Asset Details](../../data-operations/data-operation-overview/the-fetch-asset-details-data-operation) given an Asset URI looks up file details such as (name, type, size) and provides a temporary URL to download the underlying file
* [Delete Assets](../../data-operations/data-operation-overview/the-delete-assets-data-operation) removes the underlying file(s) from the server for an asset
