インテリジェントドキュメント継続とは、AI を活用したライティング支援機能です。既存のテキスト、主題、スタイルなどの条件に基づいて、首尾一貫した論理的に整合性のあるフォローアップコンテンツが自動的に生成されます。インテリジェントドキュメント継続は、ライティングの効率と質を向上させるために広く使用されています。
前提条件
続行する前に、IMM プロジェクトがバケットにマッピングされていることを確認してください。 IMM プロジェクトをマッピングする方法の詳細については、「はじめに」および「AttachOSSBucket」をご参照ください。
注意事項
インテリジェントドキュメント継続は、同期処理リクエストに対してのみ有効にできます。
リクエストを送信するには、POST メソッドを使用する必要があります。
匿名アクセスは拒否されます。
この機能を使用するには、必要な権限を持っている必要があります。 詳細については、「権限」をご参照ください。
パラメーター
操作: doc/continue
次の表にパラメーターを示します。
パラメーター | タイプ | 必須 | 説明 |
content | 文字列 | はい | 拡張するドキュメント。URL セーフで Base64 エンコードされている必要があります。 説明 処理されるドキュメントの長さは最大 19,500 バイトです。 |
format | 文字列 | いいえ | レスポンスが返される形式を指定します。 有効な値:
|
history | 文字列 | いいえ | 履歴生成の配列。URL セーフで Base64 エンコードされている必要があります。 形式:
|
次の表に、レスポンスのパラメーターを示します。
パラメーター | タイプ | 説明 |
RequestId | 文字列 | リクエストの ID。 |
Output | 構造体 | 出力。 サブノード: Text と FinishReason |
Text | 文字列 | 生成されたコンテンツ。 親ノード: Output |
FinishReason | 文字列 | 継続タスクのステータス。 有効な値:
親ノード: Output |
RESTful API の使用
RESTful API を使用してドキュメント継続タスクを実行する場合、ファイル名を指定する必要があります。これはプレースホルダーとしてのみ使用されます。 content パラメーターの値のみが、処理されるコンテンツのキャリアとして識別されます。
通常の HTTP モードを使用してインテリジェントドキュメント継続を使用する
処理方法
処理対象ファイル: example.doc
処理対象テキスト: Ernest Hemingway の「老人と海」は、老漁師サンチャゴと巨大カジキを捕まえるための壮大な闘いの物語です。 この物語は、人間の忍耐力、不屈の精神、そして自然の力との闘いについての深い探求です。 サンチャゴの逆境に立ち向かう揺るぎない決意と尊厳は、人間の精神の強さの証です。
レスポンスの形式: 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/continue,content_RXJuZXN0IEhlbWluZ3dheSdzICJUaGUgT2xkIE1hbiBhbmQgdGhlIFNlYSIgaXMgYSB0YWxlIG9mIGFuIG9sZCBmaXNoZXJtYW4sIFNhbnRpYWdvLCBhbmQgaGlzIGVwaWMgc3RydWdnbGUgdG8gY2F0Y2ggYSBnaWFudCBtYXJsaW4uIFRoaXMgc3RvcnkgaXMgYSBwcm9mb3VuZCBleHBsb3JhdGlvbiBvZiBodW1hbiBlbmR1cmFuY2UsIHBlcnNldmVyYW5jZSwgYW5kIHRoZSBiYXR0bGUgYWdhaW5zdCB0aGUgZm9yY2VzIG9mIG5hdHVyZS4gU2FudGlhZ28ncyB1bndhdmVyaW5nIGRldGVybWluYXRpb24gYW5kIGRpZ25pdHkgaW4gdGhlIGZhY2Ugb2YgYWR2ZXJzaXR5IHNlcnZlIGFzIGEgdGVzdGFtZW50IHRvIHRoZSBzdHJlbmd0aCBvZiB0aGUgaHVtYW4gc3Bpcml0Lg==サンプルレスポンス
HTTP/1.1 200 OK
Server: AliyunOSS
Date: Thu, 10 Aug 2023 11:09:00 GMT
Content-Type: application/json;charset=UTF-8
Connection: close
Vary: Accept-Encoding
x-oss-request-id: 6761445E8A0E5D383974169B
x-oss-server-time: 2010
Content-Encoding: gzip
{
"RequestId":"6761445E8A0E5D383974169B",
"Output":{
"Text":"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.\n\nSet in the Gulf Stream off the coast of Cuba, the narrative unfolds over several days, during which Santiago battles not only the mighty fish but also his own physical and mental limits. The old man has gone 84 days without catching a fish, and the village regards him as \"salao,\" the worst form of unlucky. Despite this, he sets out alone in his skiff, determined to prove his worth and restore his reputation.\n\nOn the 85th day, Santiago hooks the largest marlin he has ever seen. The ensuing struggle is both physical and psychological, as the fish pulls him far out to sea, testing his resolve and stamina. For three days and nights, Santiago holds on, enduring hunger, thirst, and the relentless strain on his body. His respect for the marlin grows with each passing hour, recognizing in the fish a kindred spirit and a worthy adversary.\n\nHemingway’s sparse, yet powerful prose captures the essence of Santiago’s journey, blending action with introspection. The old man’s reflections on life, death, and the natural world offer deep insights into the human condition. He thinks about his past, his lost youth, and the lessons he has learned over a lifetime at sea. These moments of introspection provide a counterpoint to the intense action, enriching the narrative with layers of meaning.\n\nDespite his eventual triumph in catching the marlin, Santiago’s victory is bittersweet. On his way back to shore, sharks attack and strip the marlin to a skeleton, leaving Santiago with nothing but the memory of his achievement. Yet, even in defeat, Santiago remains dignified and resilient. His journey is a testament to the idea that true success lies not in the outcome but in the effort and the character one displays in the face of overwhelming odds.\n\n\"The Old Man and the Sea\" is more than just a story about fishing; it is a universal tale of the human struggle against the inevitable challenges of life. Hemingway’s novel celebrates the indomitable human spirit and the enduring power of hope, even in the most trying circumstances. Through Santiago’s story, readers are reminded that the greatest battles are often fought within oneself, and that the true measure of a person is found in their ability to persevere.",
"FinishReason":"stop"
}
}SSE モードを使用してインテリジェントドキュメント継続を使用する
処理方法
処理対象ファイル: example.doc
処理対象テキスト: Ernest Hemingway の「老人と海」は、老漁師サンチャゴと巨大カジキを捕まえるための壮大な闘いの物語です。 この物語は、人間の忍耐力、不屈の精神、そして自然の力との闘いについての深い探求です。 サンチャゴの逆境に立ち向かう揺るぎない決意と尊厳は、人間の精神の強さの証です。
レスポンスの形式: 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/continue,format_event-stream,content_RXJuZXN0IEhlbWluZ3dheSdzICJUaGUgT2xkIE1hbiBhbmQgdGhlIFNlYSIgaXMgYSB0YWxlIG9mIGFuIG9sZCBmaXNoZXJtYW4sIFNhbnRpYWdvLCBhbmQgaGlzIGVwaWMgc3RydWdnbGUgdG8gY2F0Y2ggYSBnaWFudCBtYXJsaW4uIFRoaXMgc3RvcnkgaXMgYSBwcm9mb3VuZCBleHBsb3JhdGlvbiBvZiBodW1hbiBlbmR1cmFuY2UsIHBlcnNldmVyYW5jZSwgYW5kIHRoZSBiYXR0bGUgYWdhaW5zdCB0aGUgZm9yY2VzIG9mIG5hdHVyZS4gU2FudGlhZ28ncyB1bndhdmVyaW5nIGRldGVybWluYXRpb24gYW5kIGRpZ25pdHkgaW4gdGhlIGZhY2Ugb2YgYWR2ZXJzaXR5IHNlcnZlIGFzIGEgdGVzdGFtZW50IHRvIHRoZSBzdHJlbmd0aCBvZiB0aGUgaHVtYW4gc3Bpcml0Lg==サンプルレスポンス
HTTP/1.1 200 OK
Server: AliyunOSS
Date: Thu, 10 Aug 2023 11:20:11 GMT
Content-Type: text/event-stream;charset=UTF-8
Transfer-Encoding: chunked
Connection: close
x-oss-request-id: 67614545E3FA66313474AAC8
x-oss-server-time: 587
id: 0
event: Result
data: {"RequestId":"67614545E3FA66313474AAC8","Output":{"Text":"Er","FinishReason":"null"}}
id: 1
event: Result
data: {"RequestId":"67614545E3FA66313474AAC8","Output":{"Text":"Ernest","FinishReason":"null"}}
id: 2
event: Result
data: {"RequestId":"67614545E3FA66313474AAC8","Output":{"Text":"Ernest Hem","FinishReason":"null"}}
id: 3
event: Result
data: {"RequestId":"67614545E3FA66313474AAC8","Output":{"Text":"Ernest Heming","FinishReason":"null"}}
id: 4
event: Result
data: {"RequestId":"67614545E3FA66313474AAC8","Output":{"Text":"Ernest Hemingway's \"The","FinishReason":"null"}}
id: 5
event: Result
data: {"RequestId":"67614545E3FA66313474AAC8","Output":{"Text":"Ernest Hemingway's \"The Old Man and the","FinishReason":"null"}}
id: 6
event: Result
data: {"RequestId":"67614545E3FA66313474AAC8","Output":{"Text":"Ernest Hemingway's \"The Old Man and the Sea\" is a","FinishReason":"null"}}
id: 7
event: Result
data: {"RequestId":"67614545E3FA66313474AAC8","Output":{"Text":"Ernest Hemingway's \"The Old Man and the Sea\" is a tale of an old","FinishReason":"null"}}
id: 8
event: Result
data: {"RequestId":"67614545E3FA66313474AAC8","Output":{"Text":"Ernest Hemingway's \"The Old Man and the Sea\" is a tale of an old fisherman, Santiago","FinishReason":"null"}}
id: 9
event: Result
data: {"RequestId":"67614545E3FA66313474AAC8","Output":{"Text":"Ernest Hemingway's \"The Old Man and the Sea\" is a tale of an old fisherman, Santiago, and his epic","FinishReason":"null"}}
id: 10
event: Result
data: {"RequestId":"67614545E3FA66313474AAC8","Output":{"Text":"Ernest Hemingway's \"The Old Man and the Sea\" is a tale of an old fisherman, Santiago, and his epic struggle to catch a","FinishReason":"null"}}
id: 11
event: Result
data: {"RequestId":"67614545E3FA66313474AAC8","Output":{"Text":"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.","FinishReason":"null"}}
id: 12
event: Result
data: {"RequestId":"67614545E3FA66313474AAC8","Output":{"Text":"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","FinishReason":"null"}}
id: 13
event: Result
data: {"RequestId":"67614545E3FA66313474AAC8","Output":{"Text":"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","FinishReason":"null"}}
id: 14
event: Result
data: {"RequestId":"67614545E3FA66313474AAC8","Output":{"Text":"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,","FinishReason":"null"}}
id: 15
event: Result
data: {"RequestId":"67614545E3FA66313474AAC8","Output":{"Text":"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","FinishReason":"null"}}
id: 16
event: Result
data: {"RequestId":"67614545E3FA66313474AAC8","Output":{"Text":"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","FinishReason":"null"}}
id: 17
event: Result
data: {"RequestId":"67614545E3FA66313474AAC8","Output":{"Text":"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 unw","FinishReason":"null"}}
id: 18
event: Result
data: {"RequestId":"67614545E3FA66313474AAC8","Output":{"Text":"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","FinishReason":"null"}}
id: 19
event: Result
data: {"RequestId":"67614545E3FA66313474AAC8","Output":{"Text":"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","FinishReason":"null"}}
id: 20
event: Result
data: {"RequestId":"67614545E3FA66313474AAC8","Output":{"Text":"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","FinishReason":"null"}}
id: 21
event: Result
data: {"RequestId":"67614545E3FA66313474AAC8","Output":{"Text":"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","FinishReason":"null"}}
id: 22
event: Result
data: {"RequestId":"67614545E3FA66313474AAC8","Output":{"Text":"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","FinishReason":"null"}}
id: 23
event: Result
data: {"RequestId":"67614545E3FA66313474AAC8","Output":{"Text":"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.\n\nSantiago","FinishReason":"null"}}
id: 24
event: Result
data: {"RequestId":"67614545E3FA66313474AAC8","Output":{"Text":"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.\n\nSantiago, an experienced fish","FinishReason":"null"}}
id: 25
event: Result
data: {"RequestId":"67614545E3FA66313474AAC8","Output":{"Text":"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.\n\nSantiago, an experienced fisherman who has seen","FinishReason":"null"}}
id: 26
event: Result
data: {"RequestId":"67614545E3FA66313474AAC8","Output":{"Text":"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.\n\nSantiago, an experienced fisherman who has seen better days, has","FinishReason":"null"}}
id: 27
event: Result
data: {"RequestId":"67614545E3FA66313474AAC8","Output":{"Text":"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.\n\nSantiago, an experienced fisherman who has seen better days, has not caught a fish","FinishReason":"null"}}
id: 28
event: Result
data: {"RequestId":"67614545E3FA66313474AAC8","Output":{"Text":"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.\n\nSantiago、経験豊富な漁師でありながら、最近は不漁続きで、84 日間も魚を釣っていません","FinishReason":"null"}}
... (rest of the code block with translated comments)OSS SDK の使用
次のサンプルコードは、一般的なプログラミング言語の Object Storage Service (OSS) SDK を使用してドキュメントを拡張する方法の例を示しています。 他のプログラミング言語の SDK を使用してドキュメントを拡張する場合は、次のサンプルコードに基づいてパラメーターを変更してください。
Java
Java 3.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();
// バケットの名前を指定します。 例: examplebucket。
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/continue,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 2.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/continue,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 3.0.2 以降の OSS SDK が必要です。
package main
import (
"encoding/base64"
"encoding/json"
"fmt"
"io"
"os"
"strings"
"github.com/aliyun/aliyun-oss-go-sdk/oss"
)
// TextData はレスポンスの構造体を定義します。
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("エラー:", 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("エラー:", err)
os.Exit(-1)
}
// バケットの名前を指定します。 例: examplebucket。
bucketName := "examplebucket"
bucket, err := client.Bucket(bucketName)
if err != nil {
fmt.Println("エラー:", 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/continue,content_%v", base64.URLEncoding.EncodeToString([]byte(txt)))
// example.docx は、プレースホルダーとして使用されるバケット内のファイルです。 この機能を使用する場合、example.docx のコンテンツは読み取られません。
response, err := bucket.Do("POST", "example.docx", params, nil, strings.NewReader(data), nil)
if err != nil {
fmt.Println("エラー:", err)
os.Exit(-1)
}
defer response.Body.Close()
jsonData, err := io.ReadAll(response.Body)
if err != nil {
fmt.Println("エラー:", err)
os.Exit(-1)
}
var text TextData
err = json.Unmarshal(jsonData, &text)
if err != nil {
fmt.Println("エラー:", err)
os.Exit(-1)
}
fmt.Printf("リクエスト ID:%v\n", text.RequestId)
fmt.Printf("テキスト:%v\n", text.Output.Text)
fmt.Printf("完了理由:%v\n", text.Output.FinishReason)
}