Uploading Files

The Q2 UUX web applications do not handle large binary files well. We have a dedicated service to handle transmission of large binary files called ArdentFS (Ardent File Server). This service can receive large files and retrieve them later. You can upload and download from either the browser or from Python.

Large file upload flows (such as Loan Application or ACH files) are supported through the Ardent File class.

Uploading from Browser

Note

This is cleanly supported for Server Side Rendered forms at the moment. Client Side Rendered is possible, but not as plug and play.

Instead of uploading the file and having it pass through the online banking stack, we recommend receiving a large file into your python script by uploading the file to the ArdentFS server and then pulling it from ArdentFS on the server.

Any <input type=’file’> posted through Q2Form will be shipped off to AWS S3, with a reference to the resulting GUID keyname passed to the SDK service. In practice.

HTML:

//index.html

<input type='file' name='form-field-name'>

Note

Traditionally, the name attributes will be the reference name of the field as it is submitted to the back end, and the input value would be used as the file name in AWS. If you would like to define your own file name here, you can use the attribute “data-file-name” in the input tag instead.

Python:

//extension.py

async def submit(self):
    file_bytes = await self.download_file('filename')

There’s some logic in our frontend that overwrites file inputs with the logic we want, eventually submitting the name on S3 through a hidden form field named q2_uploadedFileKeys. self.download_file is a method that looks at self.form_fields['q2_uploadedFileKeys'] and translates it back to a file name. This means you can add multiple files and get them just as easily! If you upload more than one, q2_uploadedFileKeys will be passed multiple times, turning it into a list on the Python side.

HTML:

//index.html

<input type='file' name='filename'>
<input type='file' name='filename_two'>

Python:

//extension.py

async def submit(self):
    file_one_bytes = await self.download_file('filename')
    file_two_bytes = await self.download_file('filename_two')

Note

Input attribute ‘multiple’ is not supported at this time.

Uploading from Python

Note

Below examples expect from q2_sdk.ardent.file_upload import File in the imports

upload_file: File = File(self.logger)
aws_file_id = await upload_file.upload_from_file(
    data=file_data,
    name=file_name,
    ttl_days=1,
    content_type='application/pdf'
)

Downloading from Browser

download_file: File = File(self.logger)
browser_download_url = await download_file.get_public_download_url(
    file_key=aws_file_id,
    expiry=60,
    render_in_browser=True
)
# This url has a short expiry, so while it can be used in a browser and potentially SMS,
# do not add it to an email or secure message
return browser_download_url.proxy_url

Downloading from Python

# aws_file_id corresponds to response from upload_from_file response
file_bytes = await File(self.logger).download(aws_file_id)