Kelanjutan Dokumen Cerdas adalah fitur berbasis AI yang membantu dalam penulisan. Fitur ini menghasilkan konten lanjutan yang koheren dan konsisten secara otomatis berdasarkan teks yang ada, subjek, serta gaya. Kelanjutan Dokumen Cerdas banyak digunakan untuk meningkatkan efisiensi dan kualitas penulisan.
Prasyarat
Sebelum melanjutkan, pastikan bahwa Proyek IMM telah dipetakan ke bucket Anda. Untuk informasi lebih lanjut tentang cara memetakan Proyek IMM, lihat Memulai dan AttachOSSBucket.
Catatan
Kelanjutan Dokumen Cerdas hanya dapat diaktifkan untuk permintaan pemrosesan sinkron.
Gunakan metode POST untuk mengirim permintaan.
Akses anonim tidak diperbolehkan.
Anda harus memiliki izin yang diperlukan untuk menggunakan fitur ini. Untuk informasi lebih lanjut, lihat izin.
Parameter
Operasi: doc/continue
Tabel berikut menjelaskan parameter yang digunakan.
Parameter | Tipe | Diperlukan | Deskripsi |
content | string | Ya | Dokumen yang akan diperpanjang, yang harus aman URL dan dikodekan Base64. Catatan Dokumen yang akan diproses dapat memiliki panjang hingga 19.500 byte. |
format | string | Tidak | Menentukan format dalam respons dikembalikan. Nilai valid:
|
history | string | Tidak | Array dari generasi historis, yang harus aman URL dan dikodekan Base64. Format:
|
Tabel berikut menjelaskan parameter dalam respons:
Parameter | Tipe | Deskripsi |
RequestId | string | ID permintaan. |
Output | struct | Hasil keluaran. Subnode: Text dan FinishReason |
Text | string | Konten yang dihasilkan. Node induk: Output |
FinishReason | string | Status tugas kelanjutan. Nilai valid:
Node induk: Output |
Menggunakan RESTful API
Jika Anda menggunakan RESTful API untuk tugas kelanjutan dokumen, Anda harus menentukan nama file sebagai placeholder. Hanya nilai parameter konten yang diidentifikasi sebagai pembawa konten yang akan diproses.
Menggunakan mode HTTP biasa untuk kelanjutan dokumen cerdas
Metode pemrosesan
File yang diproses: example.doc
Teks yang diproses: "The Old Man and the Sea" karya Ernest Hemingway adalah kisah seorang nelayan tua bernama Santiago dan perjuangannya menangkap ikan marlin raksasa. Cerita ini mengeksplorasi ketahanan manusia, ketekunan, serta pertarungan melawan kekuatan alam. Keteguhan dan martabat Santiago menjadi bukti kekuatan semangat manusia.
Format respons: json
Kode contoh
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==Respons contoh
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"
}
}Menggunakan mode SSE untuk kelanjutan dokumen cerdas
Metode pemrosesan
File yang diproses: example.doc
Teks yang diproses: "The Old Man and the Sea" karya Ernest Hemingway adalah kisah seorang nelayan tua bernama Santiago dan perjuangannya menangkap ikan marlin raksasa. Cerita ini mengeksplorasi ketahanan manusia, ketekunan, serta pertarungan melawan kekuatan alam. Keteguhan dan martabat Santiago menjadi bukti kekuatan semangat manusia.
Format respons: event-stream
Kode contoh
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==Respons contoh
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, an experienced fisherman who has seen better days, has not caught a fish in eighty-four days","FinishReason":"null"}}
id: 29
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 in eighty-four days. Despite this streak","FinishReason":"null"}}
id: 30
event: Result
data: {"RequestId":"67614545E3FA66313474AAC8","Output":{"Text{"Ernest Hemingway's \"The Old Man and the Sea\" adalah kisah tentang seorang nelayan tua, Santiago, dan perjuangan epiknya untuk menangkap ikan marlin raksasa. Cerita ini merupakan eksplorasi mendalam tentang ketahanan manusia, ketekunan, dan pertarungan melawan kekuatan alam. Keteguhan dan martabat Santiago di hadapan kesulitan menjadi bukti kekuatan semangat manusia.\n\nSantiago, seorang nelayan berpengalaman yang telah melihat hari-hari lebih baik, tidak menangkap ikan selama delapan puluh empat hari. Meskipun mengalami nasib buruk ini, ia tetap optimis dan terus berlayar setiap hari, didorong oleh keyakinan mendalam pada kemampuan dirinya sendiri dan rasa hormat terhadap lautan. Ketahanannya adalah tema sentral dari novella ini, menyoroti bagaimana seseorang dapat mempertahankan harapan dan terus berusaha mencapai tujuan meskipun menghadapi kegagalan berulang kali.\n\nTitik balik dalam narasi datang ketika Santiago menangkap marlin terbesar yang pernah ia temui. Pertarungan berikutnya antara manusia dan ikan adalah ujian melelahkan dari kekuatan tekad dan keterampilan. Selama tiga hari tiga malam, Santiago memegang tali pancing, menahan kelelahan fisik dan mental, sambil melawan elemen-elemen dan tarikan tak henti-hentinya dari marlin. Perjuangan ini melambangkan kondisi manusia secara umum, di mana individu sering kali merasa berada dalam situasi yang tampaknya mustahil untuk diatasi.\n\nProsa Hemingway yang ringkas namun kuat menangkap esensi perjalanan Santiago, menekankan kesederhanaan dan kemurnian dari pencariannya. Penggunaan minimalisme oleh penulis memungkinkan pembaca fokus pada aspek emosional dan psikologis cerita, membawa mereka ke dunia Santiago dan membuat kemenangan serta penderitaannya menjadi sangat pribadi. Melalui mata Santiago, kita melihat keindahan dan kebrutalan alam, kesendirian laut, dan martabat tenang dari hidup dengan tujuan.\n\nPada akhirnya, meskipun usaha heroik Santiago, marlin tersebut dimakan oleh hiu dalam perjalanan pulang, menyisakan hanya kerangka. Namun, kemenangan sejati terletak pada semangat Santiago yang tak terkalahkan dan pelajaran yang ia sampaikan tentang pentingnya ketekunan dan kemuliaan usaha. Perjalanan pria tua ini menjadi pengingat bahwa kesuksesan tidak selalu diukur oleh hasil nyata tetapi oleh integritas dan keberanian dalam menghadapi cobaan hidup.\n\nDalam \"The Old Man and the Sea,\" Hemingway dengan cemerlang menggabungkan tema-tema kebanggaan, kekalahan, dan penebusan, menciptakan narasi abadi yang beresonansi dengan pembaca lintas generasi. Novella ini berdiri sebagai penghormatan kepada kapasitas manusia untuk bertahan dan kekuatan semangat manusia yang abadi.","FinishReason":"stop"}}
Menggunakan SDK OSS
Kode contoh berikut menunjukkan cara memperpanjang dokumen menggunakan Object Storage Service (OSS) SDK untuk beberapa bahasa pemrograman umum. Jika Anda ingin menggunakan SDK untuk bahasa lain, sesuaikan parameter berdasarkan kode contoh berikut.
Java
Diperlukan OSS SDK for Java versi 3.17.4 atau lebih tinggi.
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 {
// Tentukan endpoint wilayah tempat bucket berada.
String endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
// Tentukan ID wilayah Alibaba Cloud tempat bucket berada. Contoh: cn-hangzhou.
String region = "cn-hangzhou";
// Dapatkan kredensial akses dari variabel lingkungan. Sebelum menjalankan kode contoh, pastikan variabel lingkungan OSS_ACCESS_KEY_ID dan OSS_ACCESS_KEY_SECRET telah dikonfigurasi.
EnvironmentVariableCredentialsProvider credentialsProvider = CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();
// Tentukan nama bucket. Contoh: examplebucket.
String bucketName = "examplebucket";
// Tentukan nama file, yang hanya digunakan sebagai placeholder. Konten file ini tidak dibaca saat Anda menggunakan fitur ini.
String key ="example.docx";
// Tentukan teks yang akan diproses.
String content = "Ernest Hemingway's \"The Old Man and the Sea\" adalah kisah tentang seorang nelayan tua, Santiago, dan perjuangan epiknya untuk menangkap ikan marlin raksasa. Cerita ini merupakan eksplorasi mendalam tentang ketahanan manusia, ketekunan, dan pertarungan melawan kekuatan alam. Keteguhan dan martabat Santiago di hadapan kesulitan menjadi bukti kekuatan semangat manusia.";
String encodeContent = BinaryUtil.toBase64String(content.getBytes()).replaceAll("\\+","-")
.replaceAll("/","_").replaceAll("=","");
// Buat instance OSSClient.
// Panggil metode shutdown untuk melepaskan sumber daya saat OSSClient tidak lagi digunakan.
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);
// Buat instruksi pemrosesan untuk kelanjutan.
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("Tangkap OSSException, yang berarti permintaan Anda sampai ke OSS, "
+ "tetapi ditolak dengan respons kesalahan karena suatu alasan.");
System.out.println("Pesan Kesalahan:" + oe.getErrorMessage());
System.out.println("Kode Kesalahan:" + oe.getErrorCode());
System.out.println("ID Permintaan:" + oe.getRequestId());
System.out.println("ID Host:" + oe.getHostId());
} catch (ClientException ce) {
System.out.println("Tangkap ClientException, yang berarti klien mengalami "
+ "masalah internal serius saat mencoba berkomunikasi dengan OSS, "
+ "seperti tidak dapat mengakses jaringan.");
System.out.println("Pesan Kesalahan:" + ce.getMessage());
} catch (IOException e) {
e.printStackTrace();
} finally {
if (ossClient != null) {
ossClient.shutdown();
}
}
}
}
PHP
Diperlukan OSS SDK for PHP versi 2.7.0 atau lebih tinggi.
<?php
// Dapatkan kredensial akses dari variabel lingkungan. Sebelum menjalankan kode contoh, pastikan variabel lingkungan OSS_ACCESS_KEY_ID dan OSS_ACCESS_KEY_SECRET telah dikonfigurasi.
$ak = getenv('OSS_ACCESS_KEY_ID');
$sk = getenv('OSS_ACCESS_KEY_SECRET');
// Tentukan nama bucket. Contoh: examplebucket.
$bucket = 'examplebucket';
// Tentukan nama file, yang hanya digunakan sebagai placeholder. Konten file example.docx tidak dibaca saat Anda menggunakan fitur ini.
$objectKey = 'example.docx';
// Tentukan teks yang akan diproses.
$txt = "Ernest Hemingway's \"The Old Man and the Sea\" adalah kisah tentang seorang nelayan tua, Santiago, dan perjuangan epiknya untuk menangkap ikan marlin raksasa. Cerita ini merupakan eksplorasi mendalam tentang ketahanan manusia, ketekunan, dan pertarungan melawan kekuatan alam. Keteguhan dan martabat Santiago di hadapan kesulitan menjadi bukti kekuatan semangat manusia.";
$base64url = str_replace(['+', '/', '='], ['-', '_', ''], base64_encode($txt));
// Buat instruksi pemrosesan untuk kelanjutan.
$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
Diperlukan OSS SDK for Go versi 3.0.2 atau lebih tinggi.
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() {
// Dapatkan kredensial akses dari variabel lingkungan. Sebelum menjalankan kode contoh, pastikan variabel lingkungan OSS_ACCESS_KEY_ID, OSS_ACCESS_KEY_SECRET dan OSS_SESSION_TOKEN telah dikonfigurasi.
provider, err := oss.NewEnvironmentVariableCredentialsProvider()
if err != nil {
fmt.Println("Error:", err)
os.Exit(-1)
}
// Buat instance 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)
}
// Tentukan nama bucket. Contoh: 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
// Tentukan teks yang akan diproses.
txt := "Ernest Hemingway's \"The Old Man and the Sea\" adalah kisah tentang seorang nelayan tua, Santiago, dan perjuangan epiknya untuk menangkap ikan marlin raksasa. Cerita ini merupakan eksplorasi mendalam tentang ketahanan manusia, ketekunan, dan pertarungan melawan kekuatan alam. Keteguhan dan martabat Santiago di hadapan kesulitan menjadi bukti kekuatan semangat manusia."
// Buat instruksi pemrosesan untuk kelanjutan.
data := fmt.Sprintf("x-oss-process=doc/continue,content_%v", base64.URLEncoding.EncodeToString([]byte(txt)))
// example.docx adalah file dalam bucket yang digunakan sebagai placeholder. Konten example.docx tidak dibaca saat Anda menggunakan fitur ini.
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)
}