Knowledge Base
  • Introduction
  • Events and Actions
  • Action Panel
  • sending email
  • calling a SQL action from a client side js action
  • Accessing to translations form a server
  • Executing SQL statements from within an action
  • How to invoke a generic SQL statement defined through a SQL action
  • How to show a message dialog
  • checking for "undefined" values
  • How to add spaces to the right of a text
  • How to create a docx report and show it on the web browser Enterprise Edition only
  • How to get or set a value from the graphics control
  • How to invoke a generic SQL query defined through a business component
  • How to remove spaces to the left and right of a text
  • How to support multiple themes in a single application, accoding to a rule
  • How to set content to a Google Map linked to a grid or form
  • How to replace all occurences of a pattern from a text
  • Utility methods
  • Link auto login
  • Creation of a link for the first access of a new user without give the user a password and forcing
  • Forgot password
  • setting up default values from values coming from a filter panel
  • identifing the modified record after the alteration
  • enabling/disabling checkboxes in a grid
  • Filtering a Lookup
  • formatting a column
  • using checkboxes to select rows in grid
  • showing a summary row in grid
  • Disabling a toolbar button
  • Configuring grid exports
  • Adding filter conditions to a grid
  • Filtering the grid content from a tree
  • Filtering the tree content, starting from a filter panel linked to a grid
  • collapsing a panel
  • validating a lookup
  • accessing the authorizations set for a specific grid
  • How to design a web service
  • How to remotelly invoke an action or business component or perform a write operation through a Restf
  • how to feed a grid from a JS business component
  • converting a JS object to a JSON string
  • executing a query
  • passing parameters to a server side JS action
  • return value
  • scheduling and frequency
  • finding the right filter panel
  • checking out if a component has been defined
  • Deploying an application
  • Enquiring a table belonging to the Platform repository
  • Adding a where clause to a business component linked to grid
  • Integrating Mailchimp lists
  • Formatting a number as a currency value to use it inside an email template
  • sending email from a template
  • How to send an email
  • Error 'smtpHost' is empty
  • Linking two windows
  • How to open manually a window from another window
  • How to open manually a popup window
  • How to hide a panel in a window dinamically
  • How to manage folder panels
  • How to manage card panels
  • Predefined variables supported by Platform
  • Accessing the application parameters
  • Application Log
  • How to design a web service
  • How to import java classes in server
  • How to import java classes in server
  • How to dynamically set a value on a combo
  • 4WS.Platform
  • How to listen to events in a mobile HTML panel
  • Issues with HTTPS requests
  • How to manage row totals in grid
  • How to send to the UI a notification to execute code automatically
  • How to filter a chart by date interval
  • How to filter a grid by date interval
  • How to read a text or csv file and save data on the database
  • How to write text or csv files
  • Reading an xls file stored in the specified path
  • How to create a report with Jasper Report
  • How to customize the alert message content
  • Setting up a cluster
  • Uploading and downloading files
  • How to listen to user definition changes
  • How to auto-show a window from login
  • How to manage encrypted fields
  • How to change CSS settings for a grid row
  • Customizing a Tree Panel
  • How to execute complex queries on Google Datastore
  • Theme customization
  • Retrieve and send the log of a mobile app
  • Import Roles and Users
  • How to synchronize multiple Form panels in the same window
  • Anchor buttons
  • Properties of subpanels
  • Bulk import
  • How to display the data not found message in a grid
  • How to setup an LDAP based authentication
  • How to synchronize data from Datastore to BigQuery
  • How to synchronize data from Datastore to Google Spanner
  • How to synchronize data from Datastore to CloudSQL
  • Scrollable form list
  • How to setup SAML authentication
  • How to export data from BigQuery in streaming
  • Update Google Spreadsheet
  • How to setup OAuth2 authentication
Powered by GitBook
On this page
  • Built-in upload/preview/download feature, at column level
  • Built-in upload/preview/download feature, at control level
  • Client-side javascript function
  • Upload a file, starting from a custom window
  • Download an uploaded file
  • Preview an uploaded file

Was this helpful?

Uploading and downloading files

Platform provides a series of ways to manage files to upload, preview, download, described as follows.

Built-in upload/preview/download feature, at column level

It is possible to use a specific column of a grid to attach a file to each grid row. When clicking on the cell, a popup window is shown to manage the upload, download, preview, delete of a file; these operations inherit the authorizations at grid level: if the current user is enabled to insert a row to a grid, uploading operation is also allowed; same for the other operations.

Built-in upload/preview/download feature, at control level

It is possible to use a specific control of a form panel ( a button) to attach a file to a specific record (form content). When clicking on the button, a popup window is shown to manage the upload, download, preview, delete of a file; these operations inherit the authorizations at form level: if the current user is enabled to insert data in the form panel, uploading operation is also allowed; same for the other operations.

Client-side javascript function

When clicking on the cell, a popup window is shown to manage the upload, download, preview, delete of a file, independently of the current window shown in the UI.

uploadFile(title,enabled,fileName,dirId,beforeUploadCallback,afterUploadCallback,errorOnUploadCallback,settings);

The syntax for this function includes the following arguments:

  • title; can be null, in that case, a default title is shown

  • enabled true: upload button is enabled, false: upload button is disabled

  • fileName file name to set in the input field; if it is not empty, then a “Download” and “Preview” buttons are shown too

  • dirId directory id on the server side where saving the file to upload

  • beforeUploadCallback callback function invoked just before the uploading; format:

function({ filename: “…” }) { 
  return true|false 
};   
// false can block the uploading
// you can change the file name by working on the argument 
  • afterUploadCallback callback function invoked after the uploading; format:

function({ fileName: "….", success: true|false, message: "…" }) 
// The popup window is automatically closed just before this callback is invoked
  • errorOnUploadCallback callback function invoked in case of errors on uploading; format:

function({ error: “…” }) 
// The popup window is automatically closed just before this callback is invoked
  • settings - optional javascript object containing additional settings, expressed as attribute-value:

    • acceptMimes: a string containing a list of mime types, separated by comma; example: "image/jpg,image/png" - used to filter the content to upload

    • encriptAttachments: true|false - specify if content to upload must be encripted on the server side; in such a case, content must be undecripted when reloading it leater

    • panelId: ... // panel id related to this upload process

Through this arguments you can for instance show a modal dialog prompting the user to select a local file and upload it in the specified folder identified by dirId. After that, you could use the same modal dialog to show a previously uploaded file, through the “Download” or “Preview” buttons, in case you have filled the “fileName” arguments.

Example

uploadFile(
    "My upload", // title,
    true, // upload enabled
    "", // fileName,
    19, // dirId
    function(args) {
        var filename = args.filename;
        return true; // do not block file uploading!
    }, // beforeUploadCallback
    function(args) {
        var filename = args.filename;
    }, // afterUploadCallback
    function(args) {
        var error = args.error;
    }, // errorOnUploadCallback
    {
      acceptMimes: "image/jpg,image/png,image/gif"
    } // settings
);

Example

var yourFileName = "...";
uploadFile(
    "My upload", // title,
    false, // upload NOT enabled
    yourFileName, // fileName,
    19 // dirId
);

Upload a file, starting from a custom window

In case you need to customize completely the content of the popup window hosting your file to upload, you can define a Platform window containing a Platform Editable Panel, where you can include any type of input fields. The only constraint is to include also a File Type Field, available only with Editable Panels.

Optionally, you can fill in the advanced property File Type, with a list of allowed mime types separated by a comma (e.g. "image/jpg,image/png").

Such a special field is composed of a readonly text field containing the file name to upload and a button used to open the operating system file selection window to select the file to upload. These field provides CSS classes having this format:

x-form-text x-form-field fileuploadfield-<panelid>-<fielAttribute> x-form-file-text x-form-invalid

x-btn x-form-file-btn x-form-file-btn-fileuploadfield-<panelid>-<fieldAttribute> x-btn-noicon

The first CSS class can be used to customize the readonly text field, whereas the second one to customize the button.

Once setting up the popup window, you can add a component event to a button, in order to start the uploading process, through the uploadFileFromForm function.

You can include in this process also additional information to pass forward to the server-side. More precisely, the upload process consists of:

  • required input controls checking: in case there is one of more input fields declared mandatory and not filled, the process is interrupted and a warning message is prompted

  • the selected file is sent to the server and saved in the specified directory id; at the same time, additional information is also passed forward to the server, where a server-side javascript action is invoked as long as the file has been saved and all input data is passed forward to this action

Syntax

var ok = uploadFileFromForm(formPanel,actionId,dirId,settings,additionalSettings);

Argument

Description

formPanel

Editable panel variable (e.g. formPanelxxx), used to extract all input values

actionId

id of the server-side javascript action to invoke; this action would receive in input all field values, through the "vo" input variable, where each field value is indexed by its attribute name:

{

inputfieldAttributeName1: "....",

inputfieldAttributeName2: "....",

...

fileName: "...", // original file name

appId: "...",

actionId: ...,

dirId: ...,

type: "FILE_PATH_FIELD",

applicationId: "...",

unzip: "N",

optionalFileName: "..." // file name renamed

}

dirId

directory id where the file must be saved; such a directory can be a Platform server directory or a bucket in GCS

settings

optional: can be null; if set, it is a js object containing additional settings:

additionalSettings

optional: can be null: if set, it contains pars/vals to pass forward to the server-side js action

Settings can contain something like:

settings: {

autoDefineUploadFileName: true|false,

// true to auto-rename file according to this policy: a.pdf -> a_12345566.pdf

beforeUploadCallback: function({ filename: "..." ) {...},

// callback used to define an ad hoc file renaming policy

afterUploadCallback: function({ success: true|false, message: "...", fileName: "..." }) {...},

// callback invoked at the end of the uploading process

errorOnUploadCallback: function({ error: "..." }) {...}

// callback invoked in case of errors during the uploading process

}

Example of code which can be included in the client-side javascript action bound to a button click event, in order to start the uploading process:

uploadFileFromForm(
    formPanelxxx, // Editor Panel variable
    yyy, // actionId
    zzz, // dir id
    {
        autoDefineUploadFileName: true
    },
    {
        myId: 123 // additional parameters to pass forward to the server side action
    }
);

Download an uploaded file

Once a file has been uploaded, the easiest way to download it is through the grid/form panel from which it has been uploaded (see first section in this web page).

Anyway, it is possible to customize the download process and attach it in any part of the application UI, through the client-side javascript function provided by Platform:

downloadFile(fileName,dirId)

You need to provide to this function the file name for the file to download and its location.

Examples:

// in case of a grid having one file for each row
var selectedRow = gridxxx.getSelectionModel().getSelected();
var vo = selectedRow.data;
downloadFile(
  vo.fileName, // e.g. the attribute name containing the file name
  dirId // provided externally
);
// in case of a form having a file linked to it
var record = formxxx.getForm().record;
downloadFile(
  record.fileName, // e.g. the attribute name containing the file name
  dirId // provided externally
);

Note: pay attention in case you are storing files in GCS; in such a scenario, the directory id only identifies the bucket name, not the relative path of the file, which must be saved along with the file name itself.

Preview an uploaded file

Once a file has been uploaded, the easiest way to show it again is through the grid/form panel from which it has been uploaded (see first section in this web page).

Anyway, it is possible to customize the preview process and attach it in any part of the application UI, through the client-side javascript function provided by Platform:

previewFile(fileName,dirId,settings)

You need to provide to this function the file name for the file to download and its location.

Examples:

// in case of a grid having one file for each row
var selectedRow = gridxxx.getSelectionModel().getSelected();
var vo = selectedRow.data;
previewFile(
  vo.fileName, // e.g. the attribute name containing the file name
  dirId, // provided externally
  { // this argument can be omitted
    width: "100%", // optional
    height: 400, // optional
    title: "Preview" // optional
  }
);
// in case of a form having a file linked to it
var record = formxxx.getForm().record;
previewFile(
  record.fileName, // e.g. the attribute name containing the file name
  dirId, // provided externally
  { // this argument can be omitted
    width: "100%", // optional
    height: 400, // optional
    title: "Preview" // optional
  }
);

Note: pay attention in case you are storing files in GCS; in such a scenario, the directory id only identifies the bucket name, not the relative path of the file, which must be saved along with the file name itself.

Note: not all file formats can be showed as a preview; it depends on the browser plugins/extensions installed; it can work for most of the image formats, PDF (if Acrobat reader has been installed), text files, but it is unlikely that it can work for Office documents.

PreviousSetting up a clusterNextHow to listen to user definition changes

Last updated 4 years ago

Was this helpful?