Retrieves the preview and editing credentials for a document.
Operation description
-
Before you use this operation, make sure that you are familiar with the billing of Intelligent Media Management. For more information, see Pricing.
-
Do not perform cross-border access on OSS files. For example, if a file is stored in a bucket in the Singapore region, do not initiate preview, read, or download requests from the Chinese mainland. In such scenarios, the network link quality is significantly affected by the cross-border network environment, which may cause increased access latency, preview failures, download interruptions, or unstable connections. Network stability and access experience cannot be guaranteed. Make sure that the access point and the bucket are in the same region to avoid uncertainties caused by cross-border access.
-
The access credential expires in 30 minutes, and the refresh credential expires in 1 day.
-
The returned expiration time is in UTC, which is 8 hours behind UTC+8.
-
Supported input file formats:
Word documents: doc, docx, txt, dot, wps, wpt, dotx, docm, dotm, and rtf.
Presentation documents (PPT): ppt, pptx, pptm, ppsx, ppsm, pps, potx, potm, dpt, and dps.
Excel documents: et, xls, xlt, xlsx, xlsm, xltx, xltm, and csv.
PDF documents: pdf.
-
The maximum supported file size is 200 MB.
-
The maximum supported number of document pages is 5,000.
-
For projects created before December 1, 2023, billing is based on the number of document opens. Currently, billing is based on the number of API calls. To switch to the new billing mode, create a new project. Note that each API call can be used by only one user. If the call is reused, only the last user can access the document normally, and the access permissions of other users are revoked.
-
Activate Message Service (MNS) in the same region as Intelligent Media Management, create a topic and a queue, and configure a subscription. You can pass in the MNS topic name by using the NotifyTopicName parameter to receive message notifications about file saves. For more information about the MNS SDK, see Receive and delete messages. For an example of the JSON format of the Message field in file save message notifications, see WebOffice message notification format.
To use the versioning feature, you must first enable versioning in OSS and then set the History parameter to true. .
Try it now
Test
RAM authorization
|
Action |
Access level |
Resource type |
Condition key |
Dependent action |
|
imm:GenerateWebofficeToken |
none |
*Project
|
None | None |
Request parameters
|
Parameter |
Type |
Required |
Description |
Example |
| ProjectName |
string |
Yes |
The project name. For information about how to obtain the project name, see Create a project. |
test-project |
| SourceURI |
string |
Yes |
The OSS URI of the document to preview or edit. The OSS URI follows the format |
oss://test-bucket/test-object.docx |
| Filename |
string |
No |
The file name, which must include the file name extension. The default value is the last segment of the SourceURI parameter. Supported file name extensions (PDF supports preview only):
|
test-Object.pptx |
| CachePreview |
boolean |
No |
Specifies whether to enable cached preview.
Important Cached preview and non-cached preview have different unit prices. For more information, see the billing item description.
Important Cached preview does not support document content search or printing. Important Cached preview does not support updating cached content. |
true、false |
| Referer |
string |
No |
The OSS hotlink protection referer. Intelligent Media Management (IMM) needs to retrieve the source file from OSS. If hotlink protection is configured for OSS, IMM must pass the corresponding header to OSS to retrieve the source file. Note
Set this parameter if the bucket that stores the document has a referer configured. |
* |
| UserData |
string |
No |
The custom user data. This parameter takes effect only when the Notification parameter is specified with MNS configurations. The data is returned in asynchronous message notifications for you to associate and process message notifications within your system. Maximum length: 2,048 bytes. |
{ "id": "test-id", "name": "test-name" } |
| PreviewPages |
integer |
No |
The maximum number of pages that can be previewed. By default, no limit is imposed. The maximum value is 5,000. |
5 |
| Password |
string |
No |
The password to open the document. Note
Set this parameter if you want to preview or edit a password-protected document. |
123456 |
| ExternalUploaded |
boolean |
No |
Specifies whether uploading a file with the same name to OSS is expected behavior. Valid values:
|
false |
| NotifyTopicName |
string |
No |
Sends event notifications to you as MNS messages. This parameter specifies the MNS topic for asynchronous message notifications. |
test-topic |
| Hidecmb |
boolean |
No |
Specifies whether to hide the toolbar. This parameter is supported in document preview mode. Valid values:
|
false |
| Permission | WebofficePermission |
No |
The user permission information in JSON format. User permissions include the following options: Each option is of the Boolean type. The default value is false. Valid values: true and false.
Note
PDF supports only the preview feature. You must set the Readonly parameter to true. Note
PDF files do not support export. Note
To use the versioning feature, you must first enable versioning in OSS and then set the History parameter to true. Important Printing is not supported in cached preview. Important Historical versions can be viewed in edit mode but not in preview mode. |
|
| User | WebofficeUser |
No |
The user information. You can pass in user information from the business side, and the WebOffice page displays this information. The system distinguishes different users by User.Id. User.Name is used only for frontend display. If User.Id is not specified, the backend automatically generates a random ID. Users with different IDs are treated as different principals and cannot modify or delete each other's comments. The default format is: Unknown_RandomString. If User.Id is not specified, the user information is displayed as "Unknown" by default. |
|
| Watermark | WebofficeWatermark |
No |
The watermark information. The watermark is generated on the frontend and is not written to the source document. Different parameters passed for the same document produce different watermarks. |
|
| CredentialConfig | CredentialConfig |
No |
Leave this parameter empty unless you have specific requirements. The China authorization configuration. This parameter is optional. For more information, see Use chained authorization to access resources of other entities. |
|
| Notification | Notification |
No |
The notification configuration. Currently, only MNS is supported. For the format of asynchronous notification messages, see WebOffice message notification format. Note
Message notifications are sent when a file is saved or renamed. |
Typical scenario examples
The following examples describe some typical scenarios based on the parameter structure:
Preview a read-only file (required for previewing PDF files)
Document preview mode. The document can only be previewed and cannot be edited:
{
"ProjectName" : "test-project",
"SourceURI" : "oss://test-bucket/test-object.pdf",
"Filename" : "test-object.docx",
"PreviewPages" : "5",
"Permission" : "{'Readonly':'true'}"
}
Preview a file with an uppercase file name extension
To preview a file with an uppercase file name extension, set the Filename parameter with a lowercase extension:
{
"ProjectName" : "test-project",
"SourceURI" : "oss://test-bucket/test-object.DOCX",
"Filename" : "test-object.docx",
"PreviewPages" : "5",
"Permission" : "{'Readonly':'true'}"
}
Preview only the first 5 pages of a document
The document has 10 pages in total. Only the first 5 pages are displayed:
{
"ProjectName" : "test-project",
"SourceURI" : "oss://test-bucket/test-object.docx",
"Filename" : "test-object.docx",
"PreviewPages" : "5",
"Permission" : "{'Readonly':'true'}"
}
Set a password for document preview
Set a password for document preview, or directly open a password-protected source file without requiring a password:
{
"ProjectName" : "test-project",
"SourceURI" : "oss://test-bucket/test-object.docx",
"Filename" : "test-object.docx",
"Password" : "123456",
"Permission" : "{'Readonly':'true'}"
}
Add a watermark to document preview
Add a watermark when previewing a document:
{
"ProjectName" : "test-project",
"SourceURI" : "oss://test-bucket/test-object.docx",
"Filename" : "test-object.docx",
"Watermark" : "{'Type':'1','Value':'水印值','Font':'bold 20px Serif'}",
"Permission" : "{'Readonly':'true'}"
}
Hide the toolbar during document preview
Hide the toolbar when previewing a document:
{
"ProjectName" : "test-project",
"SourceURI" : "oss://test-bucket/test-object.docx",
"Filename" : "test-object.docx",
"Hidecmb" : "true",
"Permission" : "{'Readonly':'true'}"
}
Edit a document online with permissions to view historical versions, copy, print, and export to PDF
Edit a document online with permissions to view historical versions, copy, print, and export to PDF:
{
"ProjectName" : "test-project",
"SourceURI" : "oss://test-bucket/test-object.docx",
"Filename" : "test-object.docx",
"Permission" : "{'Readonly':'false','History':'true','Copy':'true','Print':'true','Export':'true'}"
}
```.
Response elements
|
Element |
Type |
Description |
Example |
|
object |
The Weboffice access credentials. |
||
| RequestId |
string |
The request ID. |
1759315A-CB33-0A75-A72B-62D7******** |
| WebofficeURL |
string |
The Weboffice entry URL for previewing or editing documents online. Note
This URL cannot be opened directly in a browser. You must use it together with the Weboffice JS-SDK and the access credential (AccessToken) to preview or edit documents. For more information, see Getting Started. |
https://office-cn-shanghai.imm.aliyuncs.com/office/s/dd221b2cdb44fb66e9070d1d70a8b9bbb6d6fff7?_w_tokentype=1 |
| AccessToken |
string |
The Weboffice access credential. |
2d73dd5d87524c5e8a194c3eb5******** |
| RefreshToken |
string |
The Weboffice refresh credential. |
e374995ec532432bb678074d36******** |
| AccessTokenExpiredTime |
string |
The expiration time of the access credential. The credential expires in 30 minutes. Format: YYYY-MM-DDTHH:mm:ss. |
2021-08-30T13:13:11.347146982Z |
| RefreshTokenExpiredTime |
string |
The expiration time of the refresh credential. The credential expires in 1 day. Format: YYYY-MM-DDTHH:mm:ss. |
2021-08-31T12:43:11.347146982Z |
Common errors.
The project specified by ProjectName is not found. Go to the IMM console and check whether the project exists in the region.
{
"Code": "ResourceNotFound",
"Message": "The specified resource acs:imm::xxx:project/xxx is not found"
}
```.
The User parameter is required. Check whether this parameter is specified.
{ "Code": "InvalidArgument.User", "Message": "The parameter User is required but not provided" }
The User parameter is invalid. Check whether the parameter value is in valid JSON format.
{ "Code": "InvalidJSON parsing error, User", "Message": "Specified parameter JSON parsing error, User is not valid." }
The Permission parameter is invalid. Check whether the parameter value is in valid JSON format.
{ "Code": "InvalidJSON parsing error, Permission", "Message": "Specified parameter JSON parsing error, Permission is not valid." }
The Watermark parameter is invalid. Check whether the parameter value is in valid JSON format.
{ "Code": "InvalidJSON parsing error, Watermark", "Message": "Specified parameter JSON parsing error, Watermark is not valid." }
The PreviewPages parameter format is invalid. Check the PreviewPages parameter value.
{ "Code": "InvalidPreviewPages", "Message": "Specified parameter PreviewPages is not valid." }
The OSS file specified by SourceURI does not exist. Check whether the file exists in the bucket.
{ "Code": "ResourceNotFound", "Message": "The specified resource oss://xx is not found" }
Examples
Success response
JSON format
{
"RequestId": "1759315A-CB33-0A75-A72B-62D7********",
"WebofficeURL": "https://office-cn-shanghai.imm.aliyuncs.com/office/s/dd221b2cdb44fb66e9070d1d70a8b9bbb6d6fff7?_w_tokentype=1",
"AccessToken": "2d73dd5d87524c5e8a194c3eb5********",
"RefreshToken": "e374995ec532432bb678074d36********",
"AccessTokenExpiredTime": "2021-08-30T13:13:11.347146982Z",
"RefreshTokenExpiredTime": "2021-08-31T12:43:11.347146982Z"
}
Error codes
See Error Codes for a complete list.
Release notes
See Release Notes for a complete list.