Skip to content

informat.storage File Sharing Storage Operations ​

Overview ​

Use the informat.storage object for file sharing storage operations. File sharing storage uses the S3 protocol and is stored on the file server. All files below will be stored in the shared storage.

Terminology ​

exists ​

Check if a file exists

javascript
informat.storage.exists(path);
ParameterTypeDescription
pathStringFile path

Return Value Boolean ​

Returns whether the file exists

Example

javascript
// Check if a file exists for the specified module attachment field in the current application
const path = "moduleId/fieldId/fileId";
var result = informat.storage.exists(path);
if (result) {
  console.log("File exists");
} else {
  console.log("File does not exist");
}

listFile ​

Return the list of files in a folder

javascript
informat.storage.listFile(path);
ParameterTypeDescription
pathStringFile path

Return Value Array<String> ​

Returns the list of files in the folder

Example

javascript
// Get all files of the current application
const fileList = informat.storage.listFile("/");
console.log("fileList", fileList);

Return data example:

javascript
[
    'fileId',
    'moduleId/fieldId/fileId',
    'moduleId/fieldId/fileId2',
    ...
]

move ​

Move a file from the specified path to the target path. Note: If a file with the same name exists at the target path, it will be overwritten

javascript
informat.storage.move(source, target);
ParameterTypeDescription
sourceStringSource file path
targetStringTarget path

Return Value ​

None

Example

javascript
// Move the specified file to the application root directory
const source = "moduleId/fieldId/fileId";
const target = "fileId";
informat.storage.move(source, target);

copy ​

Copy a file from the specified path to the target path. Note: If a file with the same name exists at the target path, it will be overwritten

javascript
informat.storage.copy(source, target);
ParameterTypeDescription
sourceStringSource file path
targetStringTarget path

Return Value ​

None

Example

javascript
// Create a copy of the specified file
const source = "moduleId/fieldId/fileId";
const target = "moduleId/fieldId/fileIdCopy";
informat.storage.copy(source, target);

delete ​

Delete a file

If the file corresponding to the path does not exist, the system will report a File does not exist error; If the path corresponds to a folder rather than a file, the system will report a File does not exist error;

javascript
informat.storage.delete(path);
ParameterTypeDescription
pathStringFile path

Return Value ​

None

Example

javascript
// Delete the file for the specified module attachment field in the current application
const path = "moduleId/fieldId/fileId";
informat.storage.delete(path);

deleteDirectory ​

Delete a folder

If the folder corresponding to the path does not exist, the system will report a File does not exist error; If the path corresponds to a file rather than a folder, the system will report a File does not exist error;

javascript
informat.storage.deleteDirectory(path);
ParameterTypeDescription
pathStringFolder path

Return Value ​

None

Example

javascript
// Delete all files for the specified module attachment field in the current application
const path = "moduleId/fieldId";
informat.storage.deleteDirectory(path);

download ​

Download a file from shared storage to the local sandbox environment. Note: If a file with the same name exists locally, it will be overwritten

javascript
informat.storage.download(path, localPath);
ParameterTypeDescription
pathStringFile path
localPathStringLocal sandbox environment file path

Return Value ​

None

Example

javascript
// Download the specified shared storage file to the local root directory for the current application
const path = "moduleId/fieldId/fileId";
const localPath = "local.png";
informat.storage.download(path, localPath);

upload ​

Upload a local file to shared storage. Note: If a file with the same name exists locally, it will be overwritten

javascript
informat.storage.upload(localPath, remotePath);
ParameterTypeDescription
localPathStringLocal file path
remotePathStringShared storage path

Return Value ​

None

Example

javascript
// Upload the specified local file to the shared storage root directory for the current application
const localPath = "local.png";
const remotePath = "remote.png";
informat.storage.upload(localPath, remotePath);

uploadFromURL ​

Upload a file from a remote URL to shared storage

javascript
informat.storage.uploadFromURL(url, remotePath);
ParameterTypeDescription
urlStringRemote URL
remotePathStringShared storage path

Return Value ​

None

Example

javascript
// Upload a remote file to the shared storage root directory for the current application
const url = "https:/example.com/file.jpg";
const remotePath = "file.jpg";
informat.storage.uploadFromURL(url, remotePath);

getFilePath ​

Get file path

javascript
informat.storage.getFilePath(tableKey, fieldKey, fileId);
ParameterTypeDescription
tableKeyStringData table identifier
fieldKeyStringField identifier
fileIdStringFile ID

Return Value String ​

Shared storage file path

Example

javascript
// Get the file path for the data table identifier "goods", field identifier "pic", and file ID "fileId"
const filePath = informat.storage.getFilePath("goods", "pic", "fileId");
console.log("File path---->", filePath); // File path---->goodsmoduleId/picFieldId/fileId

createFileToken ​

Create file access Token

javascript
informat.storage.createFileToken(path, fileName, expireTime);
ParameterTypeDescription
pathStringShared storage file path
fileNameStringFile name, can be empty
expireTimeIntegerExpiration time in seconds

createFileDownloadUrl ​

Create file download URL

javascript
informat.storage.createFileDownloadUrl(fileToken);
ParameterTypeDescription
fileTokenStringFile access TOKEN

createFileDownloadUrl ​

Create file download URL

javascript
informat.storage.createFileDownloadUrl(fileToken, host);
ParameterTypeDescription
fileTokenStringFile access TOKEN
hostStringWeb service address, can be empty, defaults to external network access address

convertFormat ​

Document format conversion

javascript
informat.storage.convertFormat(sourcePath, targetPath, setting);
ParameterTypeDescription
sourcePathStringPath of the document to convert
targetPathStringTarget document path after successful conversion
settingConvertSettingConversion settings

convertFormat ​

Document format conversion

javascript
informat.storage.convertFormat(sourcePath, targetPath, onlyofficeServiceUrl, setting);
ParameterTypeDescription
sourcePathStringPath of the document to convert
targetPathStringTarget document path after successful conversion
onlyofficeServiceUrlStringOnlyOffice service address, defaults to the file preview address configured in the management backend
settingConvertSettingConversion settings

The ConvertSetting structure is as follows

js
{
    async:Boolean,//Define the conversion request type: synchronous or asynchronous
    fileType:String,//Define the type of document file to be converted.
    outputtype:String,//Define the type of converted document to be generated.
    password:String,//If the document file is password protected, define the password for the file
    region:String,//Define the default display format for currency, date, and time when converting from spreadsheet format to PDF. Use a four-letter language code (en-US, fr-FR, etc.) for settings. The default value is en-US.
    title:String,//Define the filename after conversion
    spreadsheetLayout:{
        fitToHeight:Integer,//Set the height of the conversion area in pages. Default value is 0.
        fitToWidth:Integer,//Set the width of the conversion area in pages. Default value is 0.
        gridLines:Boolean,//Allow including or excluding gridlines in the output PDF file. Default value is false.
        headings:Boolean,//Allow including or excluding headings in the output PDF file. Default value is false.
        ignorePrintArea:Boolean,//Determine whether to ignore the print area selected for the spreadsheet file. Default value is true
        margins:{
            bottom:String,//Set the bottom margin of the output PDF file. Default value is 19.1 mm.
            right:String,//Set the right margin of the output PDF file. Default value is 19.1 mm.
            left:String,//Set the left margin of the output PDF file. Default value is 19.1 mm.
            top:String,//Set the top margin of the output PDF file. Default value is 19.1 mm
        },
        orientation:String,//Set the orientation of the output PDF file. Can be landscape or portrait. Default value is portrait.
        pageSize:{
            height:String,//Set the page height of the output PDF file. Default value is 297 mm.
            width:String//Set the page width of the output PDF file. Default value is 210 mm.
        },
        scale:Integer,//Allow setting the scale of the output PDF file. Default value is 100.
    },
    thumbnail:{
        /*
        Define the mode for fitting the image to the specified height and width. Supported values: 0 - Stretch the file to fit the height and width 1 - Maintain the image aspect ratio 2 - In this case, the width and height settings are not used. Instead, the metric dimensions of the page are converted to pixels at 96 dpi. For example, an A4 (210x297mm) page becomes an image with dimensions 794x1123 pixels. Default value: 2.
        */
        aspect:Integer,
        /*
        Define whether to generate a thumbnail only for the first page or for all document pages.
        If false, a zip archive containing thumbnails for all pages will be created.
        Default value is true,
        */
        first:Boolean,
        height:Integer,//Define the thumbnail height in pixels. Default value is 100
        width:Integer,//Define the thumbnail width in pixels. Default value is 100
    }
}

Supported File Conversion Table ​

Symbol Description:

  • ⬤ Indicates full support for format conversion
  • 〇 Indicates no support for format conversion

Text Document File Formats ​

Input Formatbmpdocmdocxdotmdotxepubfb2gifhtmljpgodtottpdfpdfapngrtftxt
djvu⬤〇〇〇〇〇〇⬤〇⬤〇〇⬤⬤⬤〇〇
doc⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤
docm⬤〇⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤
docx⬤⬤〇⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤
dot⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤
dotm⬤⬤⬤〇⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤
dotx⬤⬤⬤⬤〇⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤
epub⬤⬤⬤⬤⬤〇⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤
fb2⬤⬤⬤⬤⬤⬤〇⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤
fodt⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤
htm⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤
html⬤⬤⬤⬤⬤⬤⬤⬤〇⬤⬤⬤⬤⬤⬤⬤⬤
hwp⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤
hwpx⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤
mht⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤
mhtml⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤
odt⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤〇⬤⬤⬤⬤⬤⬤
ott⬤⬤⬤⬤⬤⬤⬤⬤⬤〇⬤〇⬤⬤⬤⬤⬤
oxps⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤
pages⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤
pdf⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤〇⬤⬤⬤⬤
rtf⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤〇⬤
stw⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤
sxw⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤
txt⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤〇
wps⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤
wpt⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤
xml⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤
xps⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤

Spreadsheet File Formats ​

Input Formatbmpcsvgifjpgodsotspdfpdfapngxlsmxlsxxltmxltx
csv⬤〇⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤
et⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤
ett⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤
fods⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤
numbers⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤
ods⬤⬤⬤⬤〇⬤⬤⬤⬤⬤⬤⬤⬤
ots⬤⬤⬤⬤⬤〇⬤⬤⬤⬤⬤⬤⬤
sxc⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤
xls⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤
xlsb⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤
xlsm⬤⬤⬤⬤⬤⬤⬤⬤⬤〇⬤⬤⬤
xlsx⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤〇⬤⬤
xlt⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤
xltm⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤〇⬤
xltx⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤〇
xml⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤

Presentation File Formats ​

Input Formatbmpgifjpgodpotppdfpdfapngpotmpotxppsmppsxpptmpptx
dps⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤
dpt⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤
fodp⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤
key⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤
odp⬤⬤⬤〇⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤
otp⬤⬤⬤⬤〇⬤⬤⬤⬤⬤⬤⬤⬤⬤
pot⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤
potm⬤⬤⬤⬤⬤⬤⬤⬤〇⬤⬤⬤⬤⬤
potx⬤⬤⬤⬤⬤⬤⬤⬤⬤〇⬤⬤⬤⬤
pps⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤
ppsm⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤〇⬤⬤⬤
ppsx⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤〇⬤⬤
ppt⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤
pptm⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤〇⬤
pptx⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤〇
sxi⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤⬤

Example:

Convert a file from docx format to pdf format

js
informat.storage.convertFormat("table/field/fileId", "table/field/fileId_converted", {
  filetype: "docx",
  outputtype: "pdf",
  title: "test.pdf",
});

Convert a file from docx format to png thumbnail

js
informat.storage.convertFormat("table/field/fileId", "table/field/fileId_converted", {
  filetype: "docx",
  outputtype: "png",
  title: "test.png",
  thumbnail: {
    aspect: 0,
    first: true,
    height: 150,
    width: 100,
  },
});

Convert a file from xlsx format to pdf format

js
informat.storage.convertFormat("table/field/fileId", "table/field/fileId_converted", {
  filetype: "xlsx",
  outputtype: "pdf",
  title: "test.pdf",
  region: "en-US",
  spreadsheetLayout: {
    ignorePrintArea: true,
    orientation: "portrait",
    fitToWidth: 0,
    fitToHeight: 0,
    scale: 100,
    headings: false,
    gridLines: false,
    pageSize: {
      width: "210mm",
      height: "297mm",
    },
    margins: {
      left: "17.8mm",
      right: "17.8mm",
      top: "19.1mm",
      bottom: "19.1mm",
    },
  },
});

convertFormatFromURL ​

Convert document format from remote URL

javascript
informat.storage.convertFormatFromURL(sourceURL, targetPath, setting);
ParameterTypeDescription
sourceURLStringRemote URL of the document to convert
targetPathStringTarget document path after successful conversion
settingConvertSettingConversion settings

The following is an example of converting a docx document to pdf format from a remote URL

js
informat.storage.convertFormatFromURL("https://xxx.xxx.xx/file/example.docx", "table/field/example.pdf", {
  filetype: "docx",
  outputtype: "pdf",
  title: "test.pdf",
});

convertFormatFromURL ​

Convert document format from remote URL

javascript
informat.storage.convertFormatFromURL(sourceURL, targetPath, onlyofficeServiceUrl, setting);
ParameterTypeDescription
sourceURLStringRemote URL of the document to convert
targetPathStringTarget document path after successful conversion
onlyofficeServiceUrlStringOnlyOffice service address, defaults to the file preview address configured in the management backend
settingConvertSettingConversion settings

The following is an example of converting a docx document to pdf format from a remote URL

js
informat.storage.convertFormatFromURL("https://xxx.xxx.xx/file/example.docx", "table/field/example.pdf", null, {
  filetype: "docx",
  outputtype: "pdf",
  title: "test.pdf",
});

getContent ​

Get file string content from shared storage

javascript
informat.storage.getContent(path);
ParameterTypeDescription
pathStringShared storage path
js
informat.storage.getContent("d97x4vygqxxt4/h9fdepr09gw2h/wddvtgi7md7x47du59sd0.png");

getBase64Content ​

Get file base64 encoded content from shared storage

javascript
informat.storage.getBase64Content(path);
ParameterTypeDescription
pathStringShared storage path
js
informat.storage.getBase64Content("d97x4vygqxxt4/h9fdepr09gw2h/wddvtgi7md7x47du59sd0.png");