journey.files

Version compatibility

journey.files was introduced with version 4.80.0 of the JourneyApps Runtime.

Ability to interact with files in JourneyApps.

Examples

journey.files.saveFile

journey.files.viewFile(data, filename) where data is the string or ArrayBuffer to save to the file, and filename is a string containing the name of the file created.

Saving a string:

function saveText() {
    var text = "Text to save!";
    journey.files.saveFile(text, 'my-file.txt');
}

Saving a photo:

<var name="site_entrance" type="photo" />

<capture-photo label="Site entrance" bind="site_entrance" source="camera" resolution="small" downloadable="true" />
<button show-if="site_entrance" label="Save photo" on-press="$:savePhoto()" validate="false" />
function savePhoto() {
    var buffer = view.site_entrance.toArrayBuffer();
    journey.files.saveFile(buffer, "site_entrance.jpg");
}

journey.files.viewFile

<var name="supporting_document" type="attachment" media="application/pdf" />

<capture-file label="Upload supporting document (PDF)" bind="supporting_document" downloadable="true" />
<button show-if="supporting_document" label="View File" on-press="$:viewFile()" validate="false" />
function viewFile() {
    journey.files.viewFile(view.supporting_document);
}

journey.files.openFileExternally

<var name="supporting_document" type="attachment" media="application/pdf" />

<capture-file label="Upload supporting document (PDF)" bind="supporting_document" downloadable="true" />
<button show-if="supporting_document" label="Open File Externally" on-press="$:openExternally()" validate="false" />
function openExternally() {
    try { 
        journey.files.openFileExternally(view.supporting_document); 
    } catch(e) { 
        // Fallback to viewFile 
        // Example scenario: This could occur if the app does not have file system permissions
        // Note that the container will throw an error if a user tries to call this method on an unsupported container version. We recommend performing a container version check as well.
        journey.files.viewFile(view.supporting_document)
    }
}

TypeScript apps

Synced state

Ensure that the attachment is synced, by calling journey.synchronize() before either journey.files.viewFile or journey.files.openFileExternally.

Last updated