File Storage

It is often impractical to store files within your webserver due to size or longevity reasons. As such, we have two different solutions available depending on your situation.

Cloud Storage

The first is storing files in the cloud using AWS. This is good for short term storage (a few days) and when something needs a public link. For instance, if you create a PDF from your backend, then give someone a download link on the page to pull it down onto their machine. It works in all of our environments, including the dev sandboxes. We even have a separate guide page written on it for more details: Using Ardent FS for file storage

SFTP Storage

The second option is connecting to an SFTP server to transfer and store files. This might be to transfer either into or out of your backend container.

This is good for short or long term storage, but does not provide public access. Behind the scenes, this uses the same mechanism Q2 already relies on to share files with our Financial Institutions. Your FI (or the one you are partenered with) likely has an SFTP server provided by Q2. It might have the name “GoAnywhere”, or as an older name “MoveIt”. The structure in the filesystem typically looks something like this:

/SFTPRoot
    /{ABA}
        /Inbound
            /EVE Extract
        /Outbound

The interface the FI is used to seeing will look something like this:

https://cdn.q2developer.com/sdk/docs/goanywhere.png

FIs can use the frontend to upload into that structure, then we can make that available within your container. The way we make this happen is by mounting the filesystem directly to the structure in the container, then you access it just like a directory/file in your python code.

Another way of saying that is, we will take a directory in the SFTP server (for instance /SFTPRoot/{ABA}/Inbound/YourData) and expose it within the container as /mnt/sftp. This means your code can simply read and write from there and any changes will immediately be visible within the Q2 SFTP interface.

A bare bones code snippet to interact with a file called “MyReport.csv” might therefore look like this:

def read_report(self) -> str:
    with open("/mnt/sftp/MyReport.csv", 'r') as handle:
        report_data = handle.read()
    return report_data

No need to do a network connection or know the original file path structure!

For local development, you can replace “/mnt/sftp” with your own file path, or better yet, make it a variable that can be passed in when the script is run. Either an argument if you are making an Entrypoint:

q2 read_report --path="/mnt/sftp"

or a DbConfig if you are writing an Extension:

class ReportHandler(Q2TectonServerRequestHandler):
    WEDGE_ADDRESS_CONFIGS = DbConfigList(
        [
            DbConfig("SftpPath", "/mnt/sftp")
        ]
    )