Skip to content

Attachment

Description

ItemContent
CategoryControl Class
Storage TypeTableAttachment
SortableNo
FilterableNo

Settings

SettingDescription
Allow emptySet whether the field is required
Allow multiple filesWhen enabled, multiple attachments can be uploaded. Changing this will change the field's storage type
Disallow duplicate filesWhen enabled, duplicate files will be blocked based on file content md5 check
Allow public file accessBy default, attachment file access will verify current user information. If no verification is needed, enable this option
Disallow file downloadHide file download entry
Allow viewing when the following conditions are metUse expressions to call context variables to control whether attachments are allowed to be viewed
Allow downloading when the following conditions are metUse expressions to call context variables to control whether attachments are allowed to be downloaded
Allow editing when the following conditions are metUse expressions to call context variables to control whether attachments are allowed to be edited
Display methodSet the display method for this field
Options: CardList
Allow online editing of Word/Excel/PPT filesWhen enabled, Word, Excel, and PPT files in attachments can be edited online
Attachment quantity limitSet the number of attachments that can be uploaded for this field. Limit range: 1~100
Attachment size limitSet the file size for uploaded attachments. Limit range: 0~200MB. The upper limit of the range can be modified through system background configuration
Only accept the following typesSet the format of uploaded files by setting file extensions
Only allow uploads using system camera (mobile only)When enabled, only allows attachments to be uploaded via mobile phone camera. Mobile only
Call automation after uploadProcess or intercept file uploads after files are uploaded
Automatically add image watermark to uploaded imagesWhen enabled, automatically add images as watermarks to uploaded images
Configuration content: Image watermarkImage watermark positionImage watermark rotation angleImage watermark transparency
Automatically add text watermark to uploaded imagesWhen enabled, automatically add dynamic text as watermarks to uploaded images
Configuration content: Text watermarkText watermark positionText watermark rotation angleText watermark sizeImage watermark transparencyText color

Note

  • Allow multiple files Because single attachment and multiple attachments have different storage types, enabling/disabling multiple file uploads may cause loss of some historical data. Please operate with caution.

  • Only accept the following types

    • Supported file types can use file extensions .jpg.pdf.doc, etc.; or use mime-type restrictions, such as audio/*image/*, etc. For more information, refer to
  • When the attachment field is located in a table that depends on other applications, attachments can only be accessed by concatenating links using attachment ID. The app ID is the current app ID, and the table ID or identifier is the information of the current table.

  • If the text watermark of the attachment field contains Chinese characters, please ensure that the SimSun font is installed in your system, as SimSun can correctly display Chinese characters.

  • The permission control for Allow viewing when the following conditions are met, Allow downloading when the following conditions are met, and Allow editing when the following conditions are met has higher priority than the default system configuration items. Please note that the expression must return a Boolean type false to disable the corresponding capability; other values will default to enabling the capability.

Database Storage Format

Field TypeDescription
jsonbStores JSON format data, JSON data structure is shown below

In the data table, attachment field data is stored in JSON format. If it is multiple selection, it is stored as a JSON array. The JSON structure is as follows:

ts
interface TableAttachment {
  name: string; //Name
  size: number; //Size
  id: string; //ID
  thumbnail: string; //Thumbnail
  path: string; //Path
  md5: string; //MD5 value
}

Example 1: Data stored when multiple files are not allowed (single selection)

json
{
  "id": "20ff3866fcdd4c94822301eb76a04657.jpg",
  "md5": "b394f37c3180e68090e2a0f1370f2aa9",
  "name": "test.jpg",
  "path": "uilssesqv5y7o/l6h7derr6fc6v/20ff3866fcdd4c94822301eb76a04657.jpg",
  "size": 7757,
  "thumbnail": "4923f93852594511b7c507465304cdc6.jpg"
}

Example 2: Data stored when multiple files are allowed (multiple selection)

json
[
  {
    "id": "k06s3kc79i2rtb4r225d2.docx",
    "md5": "16e5ad6839a13c51066e95b00fdd4a41",
    "name": "Platform Features.docx",
    "path": "uilssesqv5y7o/p3klf0kagl0yg/k06s3kc79i2rtb4r225d2.docx",
    "size": 735916
  },
  {
    "id": "wdn8dqk58z59jox7ywpmk.jpeg",
    "md5": "db2ce954f12e2f5b3914170a1205a912",
    "name": "cv.jpeg",
    "path": "uilssesqv5y7o/p3klf0kagl0yg/wdn8dqk58z59jox7ywpmk.jpeg",
    "size": 537100,
    "thumbnail": "cbrf1bhgfei0pbocdhg79.jpeg"
  }
]

File Storage Method

After attachments are uploaded, they are saved using the shared storage service. Informat creates folders for different fields based on application, data table, and field. The folder naming rules are as follows:

companyId/appId/tableId/fieldId
  • companyId: Company ID
  • appId: App ID
  • tableId: Table ID
  • fieldId: Field ID

Note

The above IDs are system-generated IDs, not identifiers

If the uploaded file type is an image (.png, .jpg, .jpeg, .bmp), a 200*200 pixel thumbnail will be automatically generated. The thumbnail format is jpg, and the thumbnail will be stored in the same folder as the attachment.

Access Path

The access path rules for attachments are as follows. If the file does not have Allow public access enabled, the user token needs to be passed.

Access via attachment path

text
https://host:port/web${cluster}/file/field/${appId}/${path}?token=${token}

Access via attachment ID

text
https://host:port/web${cluster}/file/field/${appId}/${tableId}/${fieldId}/${fileId}?token=${token}

Access via module, field identifier and attachment ID

text
https://host:port/web${cluster}/file/fieldkey/${appId}/${tableKey}/${fieldKey}/${fileId}?token=${token}

Call Automation After Upload

In some scenarios, we need to process files after users upload them. For example, custom image compression watermarks, file encryption, custom file format interception, etc.

Call Automation After Upload

The configured automation will be called synchronously by the server after the user uploads the file; this means that if an error occurs in the called automation, the entire user upload action will fail.

The following is an example of using automation to convert uploaded images to grayscale images:

js
function toGray(imageUrl) {
  //Use Java to convert image to grayscale
  var ImageIO = Java.type("javax.imageio.ImageIO");
  var Color = Java.type("java.awt.Color");
  var URL = Java.type("java.net.URL");
  var BufferedImage = Java.type("java.awt.image.BufferedImage");
  var ByteArrayInputStream = Java.type("java.io.ByteArrayInputStream");
  var ByteArrayOutputStream = Java.type("java.io.ByteArrayOutputStream");
  let url = new URL(imageUrl);
  let img = ImageIO.read(url);
  let w = img.getWidth(),
    h = img.getHeight();
  //Create new grayscale image canvas
  let gray = new BufferedImage(w, h, img.getType());
  let g2d = gray.createGraphics();
  g2d.setColor(null);
  g2d.fillRect(0, 0, w, h);
  for (let x = 0; x < w; x++) {
    for (let y = 0; y < h; y++) {
      //Grayscale pixel color and redraw
      let color = img.getRGB(x, y);
      let red = (color & 0xff0000) >> 16;
      let green = (color & 0xff00) >> 8;
      let blue = color & 0x0000ff;
      let avg = Math.round(red * 0.299 + green * 0.587 + blue * 0.114);
      let grayColor = new Color(avg, avg, avg);
      g2d.setColor(grayColor);
      g2d.fillRect(x, y, 1, 1);
    }
  }
  g2d.dispose();
  //
  //Replace file in shared storage
  let os = new ByteArrayOutputStream();
  ImageIO.write(gray, "jpg", os);
  let is = new ByteArrayInputStream(os.toByteArray());
  return is;
}

let ctx = automatic.getVar("ctx");
let imageUrl = informat.Misc.attachmentURL("attachmentTable", "callAutomatic", ctx.attachment.id);
//
informat.storage.uploadStream(toGray(imageUrl), ctx.attachment.path);
//Process thumbnail
let thumbnailPath = ctx.attachment.path.replace(/[^\/]+$/, ctx.attachment.thumbnail);
informat.storage.uploadStream(toGray(imageUrl), thumbnailPath);

Upload Attachments via Automation

The following is an example of using automation to upload attachments. In this example, we first use the Display custom form step to display a custom form containing an attachment field. Users upload attachments through this form, then use the following code snippet to move the uploaded attachments to the shared storage directory of the data table attachment field, and then save the moved attachment data structure by updating the data table script.

js
let record = automatic.getVar("record");
let recordId = automatic.getVar("recordId");
let att = informat.table.moveAttachment(
  "$Automatic_gai8xrg1dp62k_u6crrim3cfgo", //Custom form identifier
  "attachment", //Custom form attachment field
  "attachmentTable", //Target table identifier
  "fromAutomaticAttachment", //Target table attachment field
  record.attachment,
);
informat.table.update("attachmentTable", {
  id: recordId,
  fromAutomaticAttachment: att,
});

Batch Download

The following is an example of using automation to package multiple uploaded attachments into a zip file for batch download:

js
let recordId = automatic.getVar("recordId");
let record = informat.table.queryById("attachmentTable", recordId);
let downloadAttachments = record.downloadAttachment;
if (downloadAttachments == null || downloadAttachments.length == 0) {
  informat.app.abort("Please upload files first");
}
downloadAttachments.forEach((item) => {
  informat.storage.download(item.path, "automatic_download/" + item.name);
});
informat.file.zip("automatic_download", "automatic_download.zip");

Online Preview and Editing

Informat uses third-party document preview services to support document preview and editing functions. When users open Office files (Word, Excel, PPT), the preview service is used for display. When users open PDF, images, audio, and video files, the system's built-in preview service is used for display.

Custom Shared Storage

By default, the attachment field uses JSON format to store the metadata of uploaded files, which includes the file name, md5, path in shared storage, etc. If you need to move data between different fields, for example, moving data stored in fielda to fieldb, you need to modify the path in the metadata to the new path and copy the files in shared storage to the new path, which will generate many identical files. If the files stored in fielda and fieldb are the same, you can set the shared storage path of both fields to the same value, so that uploaded files will be stored in the same directory, and only the metadata needs to be modified when moving.

TIP

When using shared storage path, multiple fields share the same file in shared storage. If an attachment is deleted from one field, the attachment file in other fields will also become inaccessible.

Watermark

After uploading images, the system can automatically add watermarks to uploaded images. The system supports two watermark formats:

  • Text watermark (uses expressions to calculate watermark text, can set color, font size, rotation angle)
  • Image watermark (can set watermark position, transparency, rotation angle)