Skip to main content
Version: Next

Taro.openDocument(option)

Opens a file in a new page.

Reference

Type

(option: Option) => Promise<CallbackResult>

Parameters

Option

PropertyTypeRequiredDescription
filePathstringYesFile path, which can be obtained via downloadFile
fileType"doc" | "docx" | "xls" | "xlsx" | "ppt" | "pptx" | "pdf"NoFile type in which the file is opened
complete(res: any) => voidNoThe callback function used when the API call completed (always executed whether the call succeeds or fails)
fail(res: any) => voidNoThe callback function for a failed API call
success(res: Result) => voidNoThe callback function for a successful API call

fileType

Valid values of object.fileType

PropertyDescription
docdoc format
docxdocx format
xlsxls format
xlsxxlsx format
pptppt format
pptxpptx format
pdfpdf format

Sample Code

Taro.downloadFile({
url: 'https://example.com/somefile.pdf',
success: function (res) {
var filePath = res.tempFilePath
Taro.openDocument({
filePath: filePath,
success: function (res) {
console.log('File opened successfully')
}
})
}
})

API Support

APIWeChat Mini-ProgramH5React Native
Taro.openDocument✔️