Files and export
Learn how to import files, create exports, inspect attachments, and manage file and view sharing in Ninox scripts.
Files help you move data into and out of Ninox. You can import attachments, create text or spreadsheet exports, bundle files, generate links, and control who can access shared files and views. This chapter shows you the core file functions for common automation and reporting tasks.
In this chapter, you will learn how to:
Generate file, record, and view links.
Share and unshare files and saved views.
Load file content as Base64 for APIs or embedded output.
file()
Return a single file reference
files()
Return multiple file references
fileUrl()
Return a link to a file
loadFileAsBase64()
Return file content as a Base64 string
loadFileAsBase64URL()
Return file content as a Base64 data URL
shareFile()
Create a share link for a file
shareView()
Create a share link for a view
unshareAllViews()
Remove sharing from all views of a table
unshareFile()
Stop sharing a file
unshareView()
Stop sharing one saved view
Collect files
Use these functions when you want to work with one or more file objects in a script.
Return one or more file objects with file() and files()
file() and files()Use file() when you need one file reference. Use files() when you need the full list.
Use them when you want to:
Read attached files from a record.
Pass file objects to other file functions.
Work with a single file or all available files, depending on the field content.
Pick one specific attachment by filename from a record.
file(any)
file(nid, string)
files(any)
files(nid)
any: the file field, record, or supported source you want to read fromnid: the record that contains the file attachmentstring: the exact filename of the attachment you want to return
files() returns an array of file objects.
Let’s take a look at some examples:
Returns all attachments of the current record as an array.
Returns the number of attachments on the current record.
Returns the file attachment from the current record with the name "My wanted document.pdf".
Tips:
Use
files()when users can attach several files and you want all of them.Use
file()with the record ID and exact name of the file, when a record has several attachments and you need one exact file.Match the filename exactly when you use the record-and-name form.
Inspect links and URLs
Use these functions when you want to inspect a file before you use it or create a link to a file or record.
Create a link with fileUrl()
fileUrl()Use fileUrl() to return a URL for a file.
Use it when you want to:
Show or send a download link.
Return a file link after export.
Pass a file URL into another process.
Link to one specific attachment on a record.
fileUrl(file)
fileUrl(nid, string)
file: the file object for which you want a linknid: the record that contains the file attachmentstring: the exact filename of the attachment you want to link to
fileUrl() returns a link.
Let’s take a look at some examples:
Returns a link to the file.
Extracts the filename from the File field and returns a link to that specific file.
Tips:
Use the record-and-name form of
fileUrl()when a record has several attachments and you need one exact link.fileUrl()is designed for client-side use.Do not use
fileUrl()in triggers or insidedo as server,do as transaction, ordo as deferredblocks.The generated link uses information from the currently logged-in user, so it is not available in server-side execution.
Share and unshare files
Share or unshare a file with shareFile() and unshareFile()
shareFile() and unshareFile()Use shareFile() to create a share link for a file. Use unshareFile() to stop sharing it.
Use them when you want to:
Generate a shareable link for an export or attachment.
Store a file share URL in a text or URL field.
Revoke a file link that should no longer be available.
shareFile(file)
shareFile(nid, string)
unshareFile(file)
file: the file object you want to share or unsharenid: the record that contains the file you want to sharestring: the exact filename you want to share when you use the record form
shareFile() returns a link.
Let’s take a look at some examples:
Returns a share link for the exported file.
Returns a share link for the file NinoxLogo.jpg on the current record.
Stops sharing the file.
Tips:
shareFile()creates a share link, not a user-specific file permission.Save the returned link in a URL or text field when you want to reuse it later.
shareFile()does not work in a formula field because it changes data.Share links are tied to the database where they were created.
If that original database is deleted after restore or migration, old share links stop working.
Share only the final version of an export.
Share and unshare saved views
Use these functions when you want to expose or remove access to a saved view.
Manage shared views with shareView(), unshareView(), and unshareAllViews()
shareView(), unshareView(), and unshareAllViews()Use shareView() to share one saved view. Use unshareView() to stop sharing one view. Use unshareAllViews() to remove sharing from every shared view at once.
Use them when you want to:
Publish a reporting view.
Stop access to an outdated shared view.
Reset shared view access in bulk.
shareView(string)
shareView(string, string)
shareView(string, JSON)
shareView(string, string, JSON)
unshareView(string, string)
unshareAllViews(string)
string(first argument ofshareView): the table namestring(second argument of the two-string form ofshareView): the view nameJSON: optional share settings, for example,{ contentType: "pdf" }string(first argument ofunshareView): the table namestring(second argument ofunshareView): the saved view namestring(argument ofunshareAllViews): the table name
Let’s take a look at some examples:
Returns a share link for the default view of the Events table.
Returns a share link for the New York view of the Events table.
Returns a share link for the San Francisco view of the Events table as PDF.
Stops sharing the Current month view of the Invoices table.
Stops sharing all views of the Invoices table.
Tips:
If you do not specify a view, Ninox uses the default view.
shareView()returns a link that you can save in a URL or text field.shareView()supports formats such aspdf,html,csv,xlsx, andjson.shareView()does not work in a formula field because it changes data.unshareView()does not work in a formula field because it changes data.unshareAllViews()does not work in a formula field because it changes data.Use stable table and view names in scripts.
Review shared views regularly when data access matters.
Load files as Base64 for APIs and embedding
Use these functions when you need the actual file content, not just the file object or a link.
Return file content with loadFileAsBase64() and loadFileAsBase64URL()
loadFileAsBase64() and loadFileAsBase64URL()Use loadFileAsBase64() to return raw Base64 text. Use loadFileAsBase64URL() when you need a ready data: URL.
Use them when you want to:
Send file content to an API.
Embed a file in generated output.
Store binary file content as text for a follow-up request.
Read one specific attachment from a record by filename.
loadFileAsBase64(any)
loadFileAsBase64(nid, string)
loadFileAsBase64URL(any)
loadFileAsBase64URL(nid, string)
any: the file object or supported file source you want to encodenid: the record that contains the file attachmentstring: the exact filename of the attachment you want to encode
loadFileAsBase64() returns a string. loadFileAsBase64URL() returns a string.
Let’s take a look at some examples:
Returns the file content as a Base64 string.
Returns the attachment myFoto.jpg from the current record as a Base64 string.
Returns the file from the Photo field as a Base64 string.
Returns the file content as a data: URL.
Returns the attachment myPhoto.jpg from the current record as a Base64 data URL.
Returns the file from the photo field as a Base64 data URL.
Tips:
Base64 increases the payload size.
Use it only when the target system really needs inline content.
Use the record-and-name form when a record has several attachments and you need one exact file.
Use
loadFileAsBase64URL()when the target expects a readydata:URL instead of raw Base64 text.
File creation and sharing behavior can differ by client capabilities. Test export and sharing scripts in the environments your team uses most.
Last updated
Was this helpful?