目录

FileIntroduction

has.openDocument

has.openDocument(Object object)

Opens a document on a new page.

Since: 1.0.8

Parameters

The input parameter is an object containing the following fields.

Parameter Type Mandatory Description
filePath string Yes File path (local path), which can be obtained through has.downloadFile.
fileType string No Document type. The document is opened in the specified type.
success function No Callback triggered when the API call is successful.
fail function No Callback triggered when the API call fails.
complete function No Callback triggered when the API call is complete, regardless of success or failure.

Valid values of fileType

Value Description
pdf PDF.
doc DOC.
docx DOCX.
xls XlS.
xlsx XLSX.
ppt PPT.
pptx PPTX.

Error codes

Error Code Error Message
102 openDocument: fail fileType is not supported.
104 openDocument: fail no such file or directory.
126 Preview is not supported on this device.
90002401 openDocument: Failed to preview.
90002402 openDocument error.

Example:

has.downloadFile({
  url: 'https://www.example.com/xxx.pdf', // Replace the example URL with the actual URL.
  success: (res) => {
    const filePath = res.tempFilePath;
    has.openDocument({
      filePath: filePath,
      success: (res) => {
        console.info('openDocument success', res);
      },
      fail: (err) => {
        console.error('openDocument fail', err);
      },
      complete: (res) => {
        console.info('openDocument complete', res);
      }
    });
  }
});

has.getFileSystemManager

has.getFileSystemManager(): FileSystemManager

Obtains a FileSystemManager instance, which is globally unique.

Since: 1.0.4

Returns:

FileSystemManager object.

Example:

const fileSystemManager = has.getFileSystemManager();

FlagMode

Valid values of the flag parameter in the FileSystemManager.open and FileSystemManager.openSync methods.

Since: 1.0.16

Value Description
a Opens a file for appending. If the file does not exist, create one.
ax Similar to 'a'. If the file path exists, the operation fails.
a+ Opens a file for reading and appending. If the file does not exist, create one.
ax+ Similar to 'a+'. If the file path exists, the operation fails.
as Opens a file for appending (in synchronous mode). If the file does not exist, create one.
as+ Opens a file for reading and appending (in synchronous mode). If the file does not exist, create one.
r Opens a file for reading. If the file does not exist, an exception occurs.
r+ Opens a file for reading and writing. If the file does not exist, an exception occurs.
w Opens a file for writing. If the file does not exist, create one; otherwise, the file is truncated.
wx Similar to 'w'. If the file path exists, the operation fails.
w+ Opens a file for reading and writing. If the file does not exist, create one; otherwise, the file is truncated.
wx+ Similar to 'w+'. If the file path exists, the operation fails.

FileStats

Contains path and Stats.

Since: 1.0.4

Attribute Type Description
path string Path of a file or directory.
stats Stats Stats object, which describes the file status.