すべてのプロダクト
Search
ドキュメントセンター

Object Storage Service:インテリジェントドキュメントポリッシュ

最終更新日:Jun 28, 2025

インテリジェントドキュメントポリッシュ機能を使用して、ドキュメントの洗練さ、明瞭さ、および読みやすさを向上させることができます。

使用上の注意

  • インテリジェントドキュメントポリッシュは、同期処理(x-oss-process)のみをサポートしています。

  • リクエストを送信するには、POST メソッドを使用する必要があります。

  • 匿名アクセスは拒否されます。

  • この機能を使用するには、必要な権限を持っている必要があります。 詳細については、「権限」をご参照ください。

パラメーター

アクション: doc/polish

次の表にパラメーターを示します。

パラメーター

タイプ

必須

説明

content

文字列

はい

ポリッシュするコンテンツ。コンテンツは URL セーフ Base64 でエンコードする必要があります。

説明

コンテンツの長さは最大 19,500 バイトです。

format

文字列

いいえ

レスポンスを返すモード。有効な値:

  • json(デフォルト): 通常モード。完全なレスポンスを含むデータパケットが返されます。

  • event-stream: Server-Sent Events (SSE) モード。複数のパケットが返されます。各パケットには完全データが含まれています。

次の表にレスポンスパラメーターを示します。

パラメーター

タイプ

説明

RequestId

文字列

リクエスト ID。

Output

構造体

出力。

子ノード: Text と FinishReason

Text

文字列

ポリッシュされたコンテンツ。

親ノード: Output

FinishReason

文字列

ポリッシュタスクのステータス。有効な値:

  • null: タスクは実行中です。

  • stop: タスクは終了しました。

親ノード: Output

RESTful API の使用

説明

RESTful API を使用してドキュメントをポリッシュする場合、プレースホルダーとしてのみ使用されるファイル名を指定する必要があります。インテリジェントドキュメントポリッシュは、content パラメーターの値のみをポリッシュ対象のコンテンツとして識別します。

通常モードでドキュメントをポリッシュする

処理方法

  • ポリッシュ対象のファイル: example.doc

  • 推敲対象のテキスト: アーネスト・ヘミングウェイの「老人と海」は、老漁師サンチャゴと、巨大なカジキを捕まえるための壮大な闘いを描いた物語です。この物語は、人間の忍耐力、不屈の精神、そして自然の力との闘いについての深い探求です。逆境に直面しても揺るぎない決意と尊厳を保つサンチャゴの姿は、人間の精神の強さを証明するものです。

  • レスポンスフォーマット: json

リクエスト例

POST /example.doc?x-oss-process HTTP/1.1
Host: doc-demo.oss-cn-hangzhou.aliyuncs.com
Date: Fri, 28 Oct 2022 06:40:10 GMT
Authorization: OSS4-HMAC-SHA256 Credential=LTAI********************/20250417/cn-hangzhou/oss/aliyun_v4_request,Signature=a7c3554c729d71929e0b84489addee6b2e8d5cb48595adfc51868c299c0c218e

x-oss-process=doc/polish,content_RXJuZXN0IEhlbWluZ3dheSdzICJUaGUgT2xkIE1hbiBhbmQgdGhlIFNlYSIgaXMgYSB0YWxlIG9mIGFuIG9sZCBmaXNoZXJtYW4sIFNhbnRpYWdvLCBhbmQgaGlzIGVwaWMgc3RydWdnbGUgdG8gY2F0Y2ggYSBnaWFudCBtYXJsaW4uIFRoaXMgc3RvcnkgaXMgYSBwcm9mb3VuZCBleHBsb3JhdGlvbiBvZiBodW1hbiBlbmR1cmFuY2UsIHBlcnNldmVyYW5jZSwgYW5kIHRoZSBiYXR0bGUgYWdhaW5zdCB0aGUgZm9yY2VzIG9mIG5hdHVyZS4gU2FudGlhZ28ncyB1bndhdmVyaW5nIGRldGVybWluYXRpb24gYW5kIGRpZ25pdHkgaW4gdGhlIGZhY2Ugb2YgYWR2ZXJzaXR5IHNlcnZlIGFzIGEgdGVzdGFtZW50IHRvIHRoZSBzdHJlbmd0aCBvZiB0aGUgaHVtYW4gc3Bpcml0Lg==

レスポンス例

HTTP/1.1 200 OK
Server: AliyunOSS
Date: Thu, 10 Aug 2023 11:56:21 GMT
Content-Type: application/json;charset=UTF-8
Connection: close
Vary: Accept-Encoding
x-oss-request-id: 67614212960DF23035F6C49E
x-oss-server-time: 2106
Content-Encoding: gzip

{
  "RequestId":"67614212960DF23035F6C49E",
  "Output":{
    "Text":"Ernest Hemingway's \"The Old Man and the Sea\" narrates the story of an elderly fisherman, Santiago, and his monumental battle to catch a colossal marlin. This narrative delves deeply into themes of human resilience, perseverance, and the struggle against the natural world. Santiago's unyielding resolve and dignity amidst hardship stand as a powerful tribute to the indomitable human spirit.",
    "FinishReason":"stop"
  }
}

SSE モードでドキュメントをポリッシュする

処理方法

  • ポリッシュ対象のファイル: example.doc

  • 推敲対象のテキスト: アーネスト・ヘミングウェイの「老人と海」は、老漁師サンチャゴと巨大なカジキを捕まえるための壮大な闘いを描いた物語です。この物語は、人間の忍耐力、不屈の精神、そして自然の力との闘いについての深い探求です。逆境に直面しても揺るぎない決意と尊厳を保つサンチャゴの姿は、人間の精神の強さを証明するものです。

  • レスポンスフォーマット: event-stream

リクエスト例

POST /example.doc?x-oss-process HTTP/1.1
Host: doc-demo.oss-cn-hangzhou.aliyuncs.com
Date: Fri, 28 Oct 2022 06:40:10 GMT
Authorization: OSS4-HMAC-SHA256 Credential=LTAI********************/20250417/cn-hangzhou/oss/aliyun_v4_request,Signature=a7c3554c729d71929e0b84489addee6b2e8d5cb48595adfc51868c299c0c218e

x-oss-process=doc/polish,format_event-stream,content_RXJuZXN0IEhlbWluZ3dheSdzICJUaGUgT2xkIE1hbiBhbmQgdGhlIFNlYSIgaXMgYSB0YWxlIG9mIGFuIG9sZCBmaXNoZXJtYW4sIFNhbnRpYWdvLCBhbmQgaGlzIGVwaWMgc3RydWdnbGUgdG8gY2F0Y2ggYSBnaWFudCBtYXJsaW4uIFRoaXMgc3RvcnkgaXMgYSBwcm9mb3VuZCBleHBsb3JhdGlvbiBvZiBodW1hbiBlbmR1cmFuY2UsIHBlcnNldmVyYW5jZSwgYW5kIHRoZSBiYXR0bGUgYWdhaW5zdCB0aGUgZm9yY2VzIG9mIG5hdHVyZS4gU2FudGlhZ28ncyB1bndhdmVyaW5nIGRldGVybWluYXRpb24gYW5kIGRpZ25pdHkgaW4gdGhlIGZhY2Ugb2YgYWR2ZXJzaXR5IHNlcnZlIGFzIGEgdGVzdGFtZW50IHRvIHRoZSBzdHJlbmd0aCBvZiB0aGUgaHVtYW4gc3Bpcml0Lg==

レスポンス例

HTTP/1.1 200 OK
Server: AliyunOSS
Date: Thu, 10 Aug 2023 11:55:03 GMT
Content-Type: text/event-stream;charset=UTF-8
Transfer-Encoding: chunked
Connection: close
x-oss-request-id: 67614193BA82AD3732EACDFA
x-oss-server-time: 960

id: 0
event: Result
data: {"RequestId":"67614193BA82AD3732EACDFA","Output":{"Text":"Er","FinishReason":"null"}}

id: 1
// 省略

OSS SDK の使用

次のサンプルコードは、一般的なプログラミング言語の Object Storage Service (OSS) SDK を使用してドキュメントをポリッシュする方法の例を示しています。他のプログラミング言語の SDK を使用してドキュメントをポリッシュする場合は、次のサンプルコードに基づいてパラメーターを変更してください。

Java

Java V3.17.4 以降の OSS SDK が必要です。

import com.aliyun.oss.*;
import com.aliyun.oss.common.auth.*;
import com.aliyun.oss.common.comm.SignVersion;
import com.aliyun.oss.common.utils.BinaryUtil;
import com.aliyun.oss.common.utils.IOUtils;
import com.aliyun.oss.model.GenericResult;
import com.aliyun.oss.model.ProcessObjectRequest;

import java.io.IOException;
import java.util.Formatter;

public class Demo {
    public static void main(String[] args) throws ClientException, com.aliyuncs.exceptions.ClientException {
        // バケットが配置されているリージョンのエンドポイントを指定します。
        String endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
        // バケットが配置されているAlibaba CloudリージョンのIDを指定します。例: cn-hangzhou。
        String region = "cn-hangzhou";
        // 環境変数から認証情報を取得します。サンプルコードを実行する前に、OSS_ACCESS_KEY_IDおよびOSS_ACCESS_KEY_SECRET環境変数が設定されていることを確認してください。
        EnvironmentVariableCredentialsProvider credentialsProvider = CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();
        // バケットの名前を指定します。
        String bucketName = "examplebucket";
        // ファイル名を指定します。これはプレースホルダーとしてのみ使用されます。インテリジェントドキュメントポリッシュはファイルの内容を読み取りません。
        String key ="example.docx";
        // ポリッシュするテキストコンテンツを指定します。
        String content = "Ernest Hemingway's "The Old Man and the Sea" is a tale of an old fisherman, Santiago, and his epic struggle to catch a giant marlin. This story is a profound exploration of human endurance, perseverance, and the battle against the forces of nature. Santiago's unwavering determination and dignity in the face of adversity serve as a testament to the strength of the human spirit.";
        String encodeContent = BinaryUtil.toBase64String(content.getBytes()).replaceAll("\\+","-")
                .replaceAll("/","_").replaceAll("=","");

        // OSSClientインスタンスを作成します。
        // OSSClientが不要になったら、shutdownメソッドを呼び出してリソースを解放します。
        ClientBuilderConfiguration clientBuilderConfiguration = new ClientBuilderConfiguration();
        clientBuilderConfiguration.setSignatureVersion(SignVersion.V4);
        OSS ossClient = OSSClientBuilder.create()
                .endpoint(endpoint)
                .credentialsProvider(credentialsProvider)
                .clientConfiguration(clientBuilderConfiguration)
                .region(region)
                .build();

        try {

            StringBuilder sbStyle = new StringBuilder();
            Formatter styleFormatter = new Formatter(sbStyle);
            // インテリジェントドキュメントポリッシュ命令を作成します。
            styleFormatter.format("doc/polish,content_%s",
                    encodeContent);
            System.out.println(sbStyle.toString());
            ProcessObjectRequest request = new ProcessObjectRequest(bucketName, key, sbStyle.toString());
            GenericResult processResult = ossClient.processObject(request);
            String json = IOUtils.readStreamAsString(processResult.getResponse().getContent(), "UTF-8");
            processResult.getResponse().getContent().close();
            System.out.println(json);
        } catch (OSSException oe) {
            System.out.println("OSSException がキャッチされました。これは、リクエストが OSS に到達したものの、"
                    + "何らかの理由でエラー応答で拒否されたことを意味します。");
            System.out.println("エラーメッセージ:" + oe.getErrorMessage());
            System.out.println("エラーコード:" + oe.getErrorCode());
            System.out.println("リクエスト ID:" + oe.getRequestId());
            System.out.println("ホスト ID:" + oe.getHostId());
        } catch (ClientException ce) {
            System.out.println("ClientException がキャッチされました。これは、クライアントが OSS と通信しようとしているときに、"
                    + "ネットワークにアクセスできないなど、重大な内部問題が発生したことを意味します。");
            System.out.println("エラーメッセージ:" + ce.getMessage());
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (ossClient != null) {
                ossClient.shutdown();
            }
        }
    }
}

PHP

PHP V2.7.0 以降の OSS SDK が必要です。

<?php
// 環境変数から認証情報を取得します。サンプルコードを実行する前に、OSS_ACCESS_KEY_ID および OSS_ACCESS_KEY_SECRET 環境変数が設定されていることを確認してください。
$ak = getenv('OSS_ACCESS_KEY_ID');
$sk = getenv('OSS_ACCESS_KEY_SECRET');
// バケット名を指定します。例:examplebucket。
$bucket = 'examplebucket';
// ファイル名を指定します。これはプレースホルダーとしてのみ使用されます。インテリジェントドキュメントポリッシュはファイルの内容を読み取りません。
$objectKey = 'example.docx';
// ポリッシュするテキストコンテンツを指定します。
$txt = "Ernest Hemingway's "The Old Man and the Sea" is a tale of an old fisherman, Santiago, and his epic struggle to catch a giant marlin. This story is a profound exploration of human endurance, perseverance, and the battle against the forces of nature. Santiago's unwavering determination and dignity in the face of adversity serve as a testament to the strength of the human spirit.";

$base64url = str_replace(['+', '/', '='], ['-', '_', ''], base64_encode($txt));
// インテリジェントドキュメントポリッシュ命令を作成します。
$body = sprintf("x-oss-process=doc/polish,content_%s", $base64url);

$httpVerb = 'POST';
$contentMd5 = base64_encode(md5($body, true));
$contentType = '';
$date = gmdate('D, d M Y H:i:s T');
$stringToSign = $httpVerb . "\n" . $contentMd5 . "\n" . $contentType . "\n" . $date . "\n" . "/{$bucket}/{$objectKey}?x-oss-process";
$signature = base64_encode(hash_hmac('sha1', $stringToSign, $sk, true));

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://{$bucket}.oss-cn-hangzhou.aliyuncs.com/{$objectKey}?x-oss-process");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Date: ' . $date,
    'Authorization: OSS ' . $ak . ':' . $signature,
    'Content-Type: ' . $contentType,
    'Content-Md5:' . $contentMd5,
));
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);

$response = curl_exec($ch);

$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($response === false) {
    echo "Error: " . curl_error($ch);
} else {
    if ($httpcode == 200) {
        var_dump($response);
    } else {
        echo "Error: HTTP code " . $httpcode;
    }
}

Go

Go V3.0.2 以降の OSS SDK が必要です。

package main

import (
	"encoding/base64"
	"encoding/json"
	"fmt"
	"io"
	"os"
	"strings"

	"github.com/aliyun/aliyun-oss-go-sdk/oss"
)

type TextData struct {
	RequestId string `json:"RequestId"`
	Output    struct {
		Text         string `json:"Text"`
		FinishReason string `json:"FinishReason"`
	} `json:"Output"`
}

func main() {
	// 環境変数から一時的な認証情報を取得します。サンプルコードを実行する前に、OSS_ACCESS_KEY_ID、OSS_ACCESS_KEY_SECRET、および OSS_SESSION_TOKEN 環境変数が設定されていることを確認してください。
	provider, err := oss.NewEnvironmentVariableCredentialsProvider()
	if err != nil {
		fmt.Println("Error:", err)
		os.Exit(-1)
	}
	// OSSClient インスタンスを作成します。
	client, err := oss.New("https://oss-cn-hangzhou.aliyuncs.com", "", "", oss.SetCredentialsProvider(&provider), oss.AuthVersion(oss.AuthV4), oss.Region("cn-hangzhou"))
	if err != nil {
		fmt.Println("Error:", err)
		os.Exit(-1)
	}

	// バケット名を指定します。例:examplebucket。
	bucketName := "examplebucket"
	bucket, err := client.Bucket(bucketName)
	if err != nil {
		fmt.Println("Error:", err)
		os.Exit(-1)
	}
	params := make(map[string]interface{})
	params["x-oss-process"] = nil
        // 推敲するテキストコンテンツを指定します。
	txt := "Ernest Hemingway's \"The Old Man and the Sea\" is a tale of an old fisherman, Santiago, and his epic struggle to catch a giant marlin. This story is a profound exploration of human endurance, perseverance, and the battle against the forces of nature. Santiago's unwavering determination and dignity in the face of adversity serve as a testament to the strength of the human spirit."
        // インテリジェントドキュメント推敲命令を作成します。
	data := fmt.Sprintf("x-oss-process=doc/polish,content_%v", base64.URLEncoding.EncodeToString([]byte(txt)))
        // example.docx はバケット内のファイルです。プレースホルダーとして使用されます。インテリジェントドキュメント推敲はファイルの内容を読み取りません。
	response, err := bucket.Do("POST", "example.docx", params, nil, strings.NewReader(data), nil)
	if err != nil {
		fmt.Println("Error:", err)
		os.Exit(-1)
	}

	defer response.Body.Close()
	jsonData, err := io.ReadAll(response.Body)
	if err != nil {
		fmt.Println("Error:", err)
		os.Exit(-1)
	}
	var text TextData
	err = json.Unmarshal(jsonData, &text)
	if err != nil {
		fmt.Println("Error:", err)
		os.Exit(-1)
	}
	fmt.Printf("RequestId:%v\n", text.RequestId)
	fmt.Printf("Text:%v\n", text.Output.Text)
	fmt.Printf("FinishReason:%v\n", text.Output.FinishReason)
}