WebOffice online editing lets you edit Word documents, PowerPoint presentations, and Excel spreadsheets directly in a browser.
Use cases
Collaborative office platforms: Allow multiple users to edit the same document in real time.
Content management systems: Enable online document editing to create, read, update, and delete files directly within the system.
Education platforms: Allow students to submit assignments or teachers to create courseware, and save documents to the cloud for easy access and sharing.
Supported file types
File type | Extensions |
Word | doc, dot, wps, wpt, docx, dotx, docm, dotm |
PPT | ppt, pptx, pptm, ppsx, ppsm, pps, potx, potm, dpt, dps |
Excel | xls, xlt, et, xlsx, xltx, xlsm, xltm |
Usage notes
Avoid accessing OSS objects across regions. For example, if a file is stored in a bucket in the Singapore region but you request it from Chinese mainland, cross-border network conditions can degrade link quality. This may lead to increased latency, preview failures, or unstable connections, which impacts network stability and user experience. For optimal performance, ensure that the client and the bucket are in the same region.
WebOffice online editing supports only synchronous processing using the
x-oss-processparameter.
How to use
Prerequisites
In OSS, create a bucket, upload the Office document that you want to edit to the bucket, and bind an Intelligent Media Management (IMM) project to the bucket. The IMM project must be in the same region as the bucket.
You must access OSS by using a custom domain name.
NoteIf you see a message that the domain name is not on the mini program's WebView allowlist, contact Intelligent Media Management (IMM) technical support through the DingTalk group (ID: 88490020073). The support team will update the allowlist using the WeChat trusted domain validation file that you provide.
Generate an editing URL
Java
This example requires Alibaba Cloud SDK for Java 3.17.4 or later. For more information about how to install the SDK, see Installation.
package com.aliyun.oss.demo;
import com.aliyun.oss.*;
import com.aliyun.oss.common.auth.*;
import com.aliyun.oss.common.comm.SignVersion;
import com.aliyun.oss.model.GeneratePresignedUrlRequest;
import java.net.URL;
import java.util.Date;
public class Demo {
public static void main(String[] args) throws Throwable {
// Specify your custom domain name. Example: http://static.example.com.
String endpoint = "http://static.example.com";
// Obtain credentials from environment variables. Before you run this sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured.
EnvironmentVariableCredentialsProvider credentialsProvider = CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();
// Specify the bucket name. Example: examplebucket.
String bucketName = "examplebucket";
// Specify the full path of the object. If the object is not in the root directory of the bucket, you must specify the full path.
String objectName = "exampledir/exampleobject.docx";
// Specify the region where the bucket is located. For example, for China (Hangzhou), set the region to cn-hangzhou.
String region = "cn-hangzhou";
// Create an OSSClient instance.
// Call the shutdown method to release resources when the OSSClient instance is no longer needed.
ClientBuilderConfiguration clientBuilderConfiguration = new ClientBuilderConfiguration();
// Set supportCname to true to enable CNAME.
clientBuilderConfiguration.setSupportCname(true);
// Explicitly declare that Signature Version 4 is used.
clientBuilderConfiguration.setSignatureVersion(SignVersion.V4);
OSS ossClient = OSSClientBuilder.create()
.endpoint(endpoint)
.credentialsProvider(credentialsProvider)
.clientConfiguration(clientBuilderConfiguration)
.region(region)
.build();
try {
// Specify document processing parameters.
String style = "doc/edit,export_1,print_1/watermark,text_5YaF6YOo6LWE5paZ,size_30,t_60";
// Set the expiration time of the signed URL to 3,600 seconds.
Date expiration = new Date(new Date().getTime() + 3600 * 1000L );
GeneratePresignedUrlRequest req = new GeneratePresignedUrlRequest(bucketName, objectName, HttpMethod.GET);
req.setExpiration(expiration);
req.setProcess(style);
URL signedUrl = ossClient.generatePresignedUrl(req);
System.out.println(signedUrl);
} catch (OSSException oe) {
System.out.println("Caught an OSSException, which means your request made it to OSS, "
+ "but was rejected with an error response for some reason.");
System.out.println("Error Message:" + oe.getErrorMessage());
System.out.println("Error Code:" + oe.getErrorCode());
System.out.println("Request ID:" + oe.getRequestId());
System.out.println("Host ID:" + oe.getHostId());
} catch (ClientException ce) {
System.out.println("Caught an ClientException, which means the client encountered "
+ "a serious internal problem while trying to communicate with OSS, "
+ "such as not being able to access the network.");
System.out.println("Error Message:" + ce.getMessage());
} finally {
if (ossClient != null) {
ossClient.shutdown();
}
}
}
}Python
This example requires Alibaba Cloud SDK for Python 2.18.4 or later. For more information about how to install the SDK, see Installation (Python SDK V1).
# -*- coding: utf-8 -*-
import oss2
from oss2.credentials import EnvironmentVariableCredentialsProvider
# Obtain credentials from environment variables. Before you run this sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured.
auth = oss2.ProviderAuthV4(EnvironmentVariableCredentialsProvider())
# Specify the bucket name.
bucket_name = 'examplebucket'
# Specify your custom domain name. Example: https://static.example.com.
endpoint = 'https://static.example.com'
# Specify the Alibaba Cloud region ID.
region = 'cn-hangzhou'
# Initialize the bucket using the custom domain name.
bucket = oss2.Bucket(auth, endpoint, bucket_name, is_cname=True, region=region)
# Specify the object to process.
key = 'example.docx'
# Specify the expiration time in seconds.
expire_time = 3600
# Construct the processing instruction for online editing.
image_process = 'doc/edit,export_1,print_1/watermark,text_5YaF6YOo6LWE5paZ,size_30,t_60'
# Generate a signed URL that contains processing parameters.
url = bucket.sign_url('GET', key, expire_time, params={'x-oss-process': image_process}, slash_safe=True)
# Print the signed URL.
print(url)Go
This example requires Alibaba Cloud SDK for Go 3.0.2 or later. For more information about how to install the SDK, see Install OSS Go SDK.
package main
import (
"context"
"flag"
"log"
"time"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
)
// Define global variables.
var (
region string // The region.
bucketName string // The bucket name.
objectName string // The object name.
)
// The init function is used to initialize command-line parameters.
func init() {
flag.StringVar(®ion, "region", "", "The region in which the bucket is located.")
flag.StringVar(&bucketName, "bucket", "", "The name of the bucket.")
flag.StringVar(&objectName, "object", "", "The name of the object.")
}
func main() {
// Parse command-line parameters.
flag.Parse()
// Check whether the bucket name is empty.
if len(bucketName) == 0 {
flag.PrintDefaults()
log.Fatalf("invalid parameters, bucket name required")
}
// Check whether the region is empty.
if len(region) == 0 {
flag.PrintDefaults()
log.Fatalf("invalid parameters, region required")
}
// Check whether the object name is empty.
if len(objectName) == 0 {
flag.PrintDefaults()
log.Fatalf("invalid parameters, object name required")
}
// Load the default configuration and set the credential provider and region.
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion(region).
// Specify your custom domain name. Example: http://static.example.com.
WithEndpoint("http://static.example.com").
WithUseCName(true)
// Create an OSS client.
client := oss.NewClient(cfg)
// Generate a presigned URL for GetObject.
result, err := client.Presign(context.TODO(), &oss.GetObjectRequest{
Bucket: oss.Ptr(bucketName),
Key: oss.Ptr(objectName),
// Specify document processing parameters.
Process: oss.Ptr("doc/edit,export_1,print_1/watermark,text_5YaF6YOo6LWE5paZ,size_30,t_60"),
}, oss.PresignExpires(10*time.Minute))
if err != nil {
log.Fatalf("failed to get object presign %v", err)
}
log.Printf("request method:%v\n", result.Method)
log.Printf("request expiration:%v\n", result.Expiration)
log.Printf("request url:%v\n", result.URL)
if len(result.SignedHeaders) > 0 {
// If the response includes signed headers, you must include them in the GET request that uses the signed URL to prevent signature mismatch errors.
log.Printf("signed headers:\n")
for k, v := range result.SignedHeaders {
log.Printf("%v: %v\n", k, v)
}
}
}Node.js
This example requires Alibaba Cloud SDK for Node.js 8.0 or later. For more information about how to install the SDK, see Installation (Node.js SDK).
const OSS = require("ali-oss");
// Define a function to generate a signed URL.
async function generateSignatureUrl(fileName) {
// Obtain the signed URL.
const client = await new OSS({
// Specify your custom domain name. Example: http://static.example.com.
endpoint: 'http://static.example.com',
// Obtain credentials from environment variables. Before you run this sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured.
accessKeyId: process.env.OSS_ACCESS_KEY_ID,
accessKeySecret: process.env.OSS_ACCESS_KEY_SECRET,
bucket: 'examplebucket',
// Specify the region where the bucket is located. For example, for China (Hangzhou), set the region to oss-cn-hangzhou.
region: 'oss-cn-hangzhou',
authorizationV4: true,
cname: true
});
// Generate a signed URL that contains document processing parameters.
return await client.signatureUrlV4('GET', 3600, {
headers: {}, // Set request headers based on your actual request.
queries: {
"x-oss-process": "doc/edit,export_1,print_1/watermark,text_5YaF6YOo6LWE5paZ,size_30,t_60" // Add document processing parameters.
}
}, fileName);
}
// Call the function and pass a file name.
generateSignatureUrl('yourFileName').then(url => {
console.log('Generated Signature URL:', url);
}).catch(err => {
console.error('Error generating signature URL:', err);
});
PHP
This example requires Alibaba Cloud SDK for PHP 2.7.0 or later. For more information about how to install the SDK, see Installation (PHP SDK V1).
<?php
if (is_file(__DIR__ . '/../autoload.php')) {
require_once __DIR__ . '/../autoload.php';
}
if (is_file(__DIR__ . '/../vendor/autoload.php')) {
require_once __DIR__ . '/../vendor/autoload.php';
}
use OSS\OssClient;
use OSS\Core\OssException;
use OSS\Http\RequestCore;
use OSS\Http\ResponseCore;
use OSS\Credentials\EnvironmentVariableCredentialsProvider;
// Obtain credentials from environment variables. Before you run this sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured.
$provider = new EnvironmentVariableCredentialsProvider();
//Specify your custom domain name. Example: http://static.example.com.
$endpoint = "http://static.example.com";
// Specify the bucket name. Example: examplebucket.
$bucket = "examplebucket";
// If the document is in the root directory of the bucket, specify only the document name. Otherwise, specify the full path. Example: exampledir/example.docx.
$object = 'example.docx';
$config = array(
"provider" => $provider,
"endpoint" => $endpoint,
"signatureVersion" => OssClient::OSS_SIGNATURE_VERSION_V4,
"cname" => true,
"region"=> "cn-hangzhou"
);
$ossClient = new OssClient($config);
// Generate a signed URL that contains processing parameters. The URL is valid for 3,600 seconds and can be directly accessed in a browser.
$timeout = 3600;
$options = array(
// Construct the processing instruction for online editing.
OssClient::OSS_PROCESS => "doc/edit,export_1,print_1/watermark,text_5YaF6YOo6LWE5paZ,size_30,t_60");
$signedUrl = $ossClient->signUrl($bucket, $object, $timeout, "GET", $options);
print("url: \n" . $signedUrl);The following is an example of a generated signed URL:
http://static.example.com/example.docx?x-oss-process=doc%2Fedit%2Cexport_1%2Cprint_1%2Fwatermark%2Ctext_5YaF6YOo6LWE5paZ%2Csize_30%2Ct_60&x-oss-date=20250220T095032Z&x-oss-expires=3600&x-oss-signature-version=OSS4-HMAC-SHA256&x-oss-credential=LTAI********************%2F20250122%2Fcn-hangzhou%2Foss%2Faliyun_v4_request&x-oss-signature=514ed93accdb80921c4b2897c6147fdb1599308c6457f68ee0ac2f771c7d0312Copy the generated URL into your browser's address bar and press Enter to open the document for editing.
Parameters
Action: doc/edit
The following table describes the parameters.
Parameter | Type | Required | Description |
int | No | Specifies whether printing is allowed. Valid values:
| |
export | int | No | Specifies whether exporting to PDF is allowed. Valid values:
|
watermark | string | No | The watermark parameters. |
text | string | No | The watermark text. The value must be URL-safe Base64 encoded. For more information, see Watermark encoding. We recommend that you use a base64url encoder. Parent: watermark |
size | int | No | The font size of the watermark text. The value must be an integer greater than 0. Parent: watermark |
t | int | No | The opacity of the watermark text. Valid values: 0 to 100. Default value: 100. Parent: watermark |
color | string | No | The color of the watermark text, specified as an RGB hex value. The default value is #FFFFFF. Example: #000000 for black and #FFFFFF for white. Parent: watermark |
rotate | int | No | The angle of clockwise rotation. Valid values: 0 to 360. Default value: 0. The default value is 0, indicating no rotation. Parent: watermark |
type | string | No | The font of the watermark text. The value must be URL-safe Base64 encoded. For more information, see Watermark encoding. We recommend that you use a base64url encoder. The following fonts are supported:
Parent: watermark |
API reference
The preceding operations use SDKs. For greater customization, you can make direct REST API requests, which require you to manually calculate the signature. For information about how to calculate the Authorization request header, see Signature Version 4 (recommended).
Example scenario
Document to edit: example.docx
Watermark information for the editing page:
Watermark type: Text
Watermark text: Internal Material
Watermark font size: 30
Watermark opacity: 60
Permissions for the editing page: Allow export and print
Request example
GET /example.docx?x-oss-process=doc/edit,export_1,print_1/watermark,text_5YaF6YOo6LWE5paZ,size_30,t_60 HTTP/1.1
Host: doc-demo.oss-cn-hangzhou.aliyuncs.com
Date: Fri, 28 Oct 2022 06:40:10 GMT
Authorization: SignatureValuePermissions
By default, an Alibaba Cloud account has all permissions. By default, RAM users and RAM roles have no permissions. An Alibaba Cloud account or a RAM user with administrative rights must grant them permissions by using a RAM policy or a bucket policy.
API | Action | Description |
GetObject |
| Required to download an object. |
| Required when you download a specific object version by using the | |
| Required if the object is encrypted by using SSE-KMS. |
API | Action | Description |
N/A |
| Required to process data by using IMM through OSS. |
API | Action | Description |
GenerateWebofficeToken |
| Required to obtain WebOffice credentials. |
RefreshWebofficeToken |
| Required to refresh WebOffice credentials. |
Billing
WebOffice online editing incurs charges for the following billable items. For pricing details, see OSS Pricing and Billable items.
|
API |
Billable item |
Description |
|
GetObject |
GET requests |
You are charged request fees based on the number of successful requests. |
|
Outbound traffic over the Internet |
If you call the GetObject operation by using a public endpoint, such as oss-cn-hangzhou.aliyuncs.com, or an acceleration endpoint, such as oss-accelerate.aliyuncs.com, you are charged fees for outbound traffic over the Internet based on the data size. |
|
|
Retrieval of IA objects |
If IA objects are retrieved, you are charged IA data retrieval fees based on the size of the retrieved IA data. |
|
|
Retrieval of Archive objects in a bucket for which real-time access is enabled |
If you retrieve Archive objects in a bucket for which real-time access is enabled, you are charged Archive data retrieval fees based on the size of retrieved Archive objects. |
|
|
Transfer acceleration fees |
If you enable transfer acceleration and use an acceleration endpoint to access your bucket, you are charged transfer acceleration fees based on the data size. |
|
API |
Billable item |
Description |
|
GenerateWebofficeToken |
DocumentWebofficeEdit |
You are charged document processing fees based on the number of API calls. Important
You are charged for editing a document online based on the number of times the document is opened for projects created before December 1, 2023, and based on the number of API calls for projects created on and after this date. |
|
RefreshWebofficeToken |