User Manual

GETTING STARTED


OTHER EDITIONS


LAUNCHERS


MODULES


PLATFORM


APPENDIX


TUTORIALS & HELPFUL TRICKS


STRATEGIC PARTNER LINKS

Sepasoft - MES Modules
Cirrus Link - MQTT Modules

RESOURCES

Inductive University
Ignition Demo Project
Knowledge Base Articles
Forum
IA Support

ALL USER MANUAL VERSIONS

Ignition 8.1. Offline Version (04/2021)
Ignition 8 Online Version
Ignition 7.9 Online Version
Ignition 7.8 Online Version

Deprecated Pages

SDK Documentation

Employees

Sign In

Skip to end of metadata
Go to start of metadata

This function is used in Python Scripting.

Description

Opens the file found at path filename, and reads the entire file. Returns the file as an array of bytes. Commonly this array of bytes is uploaded to a database table with a column of type BLOB (Binary Large OBject). This upload would be done through an INSERT or UPDATE SQL statement run through the system.db.runPrepUpdate function. You could also write the bytes to another file using the system.file.writeFile function, or send the bytes as an email attachment using system.net.sendEmail.

Note: This function is scoped for Perspective Sessions, but since all scripts in Perspective run on the Gateway, the file must be located on the Gateway's file system. 

Client Permission Restrictions

This scripting function has no Client Permission restrictions.

Syntax

system.file.readFileAsBytes(filepath)

  • Parameters

String filepath - The path of the file to read.

  • Returns

List[Byte] - The contents of the file as an array of bytes.

  • Scope

Gateway, Vision Client, Perspective Session

Code Examples
Code Snippet
# This code prompts the user to choose a file. If the user chooses a file, that file is read and 
# uploaded to a database table called Files into a BLOB column called file_data.
 
path = system.file.openFile()
if path != None:
   bytes = system.file.readFileAsBytes(path)
   system.db.runPrepUpdate("INSERT INTO Files (file_data) VALUES (?)", [bytes])
Keywords

system file readFileAsBytes, file.readFileAsBytes