Links

journey.files

Version compatibility
journey.files was introduced with version 4.80.0 of the JourneyApps Runtime.
Ability to interact with files in JourneyApps.
Property
Description
Example
saveFile
Saves a file to the device.
Note: Due to limitations on mobile file systems, this method is only supported on Desktop and Web.
See below
viewFile
Opens a file viewer in-app to display an attachment.
Note: Supported file types: .jpg/.jpeg, .png, and pdf.
See below
openFileExternally
Opens the default file viewer (based on media type) of the device to display an attachment. Supported file types for RealWear: .jpg/.jpeg, .png, .bmp, .webp, .gif, .pdf.
Note:
  • Supported in JourneyApps Container version 22.2.1 and Runtime version 4.84.0 and later.
  • This method is currently not supported on Web.
See below

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
  • Be sure to use the "@journeyapps/runtime-build": "^2.0.2" package version (or greater) in package.json
  • After updating package.json, run the Update yarn.lock > App package action.
Synced state
Ensure that the attachment is synced, by calling journey.synchronize() before either journey.files.viewFile or journey.files.openFileExternally.