Sử dụng thông báo sự kiện để tóm tắt tệp PDF khi tải lên Use event notification to summarize PDF files on upload ការប្រើប្រាស់ការប្រកាសប្រកាសប្រកាសប្រកាសដើម្បីបញ្ជាក់ឯកសារ PDF នៅលើការផ្ទុក
Hướng dẫn chi tiết đồng bộ từ docs Cloudflare — mỗi section có backlink tới đúng vị trí trên trang gốc. Detailed guide synced from Cloudflare docs — each section links to the matching anchor on the official page. មគ្គុទ្ទេសក៍លម្អិតធ្វើសមកាលពី docs Cloudflare — ផ្នែកនីមួយៗមានតំណទៅទីតាំងត្រូវគ្នានៅទំព័រផ្លូវការ។
← Danh mục ← Catalog ← បញ្ជីGiải thích nhanh Quick context បរិបទរហ័ស
Thuộc Developer Platform — thực hành triển khai code, API và dữ liệu trên edge/serverless. Tutorial «Sử dụng event notification to summarize PDF files on upload» giúp bạn làm quen luồng triển khai thật — phù hợp đọc trước khi mở tài liệu gốc tiếng Anh. Docs gốc chia khoảng 11 bước chính; bản tóm tắt dưới đây giúp bạn nắm khung trước khi làm theo từng lệnh.
Use event notification to summarize PDF files on upload. Use Workers AI to summarize the PDF and store the summary as a text file.
ប្រព័ន្ធ ប្រតិបត្តិការ ប្រតិបត្តិការ ប្រតិបត្តិការ ប្រតិបត្តិការ ប្រតិបត្តិការ ប្រតិបត្តិការ ប្រតិបត្តិការ ប្រតិបត្តិការ ប្រតិបត្តិការ ប្រតិបត្តិការ ប្រតិបត្តិការ ប្រតិបត្តិការ ប្រតិបត្តិការ ប្រតិបត្តិការ ប្រតិបត្តិការ ប្រតិបត្តិការ ប្រតិបត្តិការ ប្រតិបត្តិការ ប្រតិបត្តិការ ប្រើ Workers AI ដើម្បីបញ្ចប់ PDF និងផ្ទុកបញ្ចប់ជាឯកសារសៀវភៅ។
Lưu ý Note ចំណាំ
Lưu ý trước khi làm Notes before you start ចំណាំមុនពេលចាប់ផ្តើម
- Đây là bản tóm tắt trên Orange Cloud Learning Hub — không thay thế tài liệu chính thức.
- Luôn mở liên kết «Tài liệu gốc» bên dưới khi cần lệnh CLI, snippet code và ảnh minh họa đầy đủ.
- Cần tài khoản Cloudflare, Wrangler CLI và (thường) hoàn thành hướng dẫn Get started của Workers/Pages.
- Docs Cloudflare cập nhật thường xuyên — đối chiếu ngày «Rà soát lần cuối» trên trang gốc khi triển khai production.
- This is a summary on Orange Cloud Learning Hub — it does not replace the official documentation.
- Open the Official docs link below for CLI commands, code snippets, and full screenshots.
- Requires a Cloudflare account, Wrangler CLI, and (typically) completing the Workers/Pages Get started guide.
- Cloudflare docs change frequently — verify the Last reviewed date on the official page before production use.
- នេះគឺជាការបញ្ជាក់អំពី Orange Cloud Learning Hub — វាគឺជាការផ្លាស់ប្តូរនៃឯកសារផ្លូវការ។
- ចុចតំណភ្ជាប់ Docs Official នៅខាងក្រោមសម្រាប់ការបញ្ជា CLI, សៀវភៅកូដនិងរូបថតពេញលេញ។
- តម្រូវឱ្យមានគណនី Cloudflare, Wrangler CLI និង (ប្រហែលជា) ការបញ្ចប់គណនី Workers/Pages Get started ។
- Cloudflare បានផ្លាស់ប្តូរជាធម្មតានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅ។
Tài liệu gốc — rà soát lần cuối: over 1 year ago Official docs — last reviewed: over 1 year ago ឯកសារផ្លូវការ — ពិនិត្យចុងក្រោយ: over 1 year ago
Overview Overview Overview
Trong tutorial này, bạn sẽ use event notifications to process a PDF file when it is uploaded to an R2 bucket. You will use Workers AI to summarize the PDF and store the summary as a text file in the same bucket.
Read the "Overview" section below — open the official docs link for full screenshots and configuration tabs.
អានផ្នែក «Overview» ខាងក្រោម — បើកតំណ docs ផ្លូវការសម្រាប់រូបភាព និង tab កំណត់។
Liên kết liên quan (docs Cloudflare) Related links (Cloudflare docs) តំណពាក់ព័ន្ធ (docs Cloudflare)
Điều kiện Prerequisites គោលបំណង
Phần «Yêu cầu trước» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.
Read the "Prerequisites" section below — open the official docs link for full screenshots and configuration tabs.
អានផ្នែក «គោលបំណង» ខាងក្រោម — បើកតំណ docs ផ្លូវការសម្រាប់រូបភាព និង tab កំណត់។
- Một Cloudflare account ↗ với access đến R2.
- Có một hộp R2 hiện có. Nhắc đến Get started tutorial for R2
- Cài đặt Node.js ↗
- A Cloudflare account ↗ with access to R2.
- Have an existing R2 bucket. Refer to Get started tutorial for R2.
- Install Node.js ↗.
- មួយ Cloudflare account ↗ ជាមួយ access ទៅ R2 ។
- មានកញ្ចប់ R2 ដែលមាន។ សូមអរគុណ Get started tutorial for R2
- ទាញយក Node.js ↗ ។
16.17.0 hoặc mới hơn.Liên kết liên quan (docs Cloudflare) Related links (Cloudflare docs) តំណពាក់ព័ន្ធ (docs Cloudflare)
1.Điều Tạo một dự án mới 1. Create a new project 1 ។ បង្កើតគម្រោងថ្មី
Bạn sẽ create a new Worker project that will use Static Assets to serve the front-end of your application. A user can upload a PDF file using this front-end, which will then be processed by your Worker.
Read the "1. Create a new project" section below — open the official docs link for full screenshots and configuration tabs.
អានផ្នែក «1 ។ បង្កើតគម្រោងថ្មី» ខាងក្រោម — បើកតំណ docs ផ្លូវការសម្រាប់រូបភាព និង tab កំណត់។
npm create cloudflare@latest -- pdf-summarizer yarn create cloudflare pdf-summarizer pnpm create cloudflare@latest pdf-summarizer - Đối với Bạn muốn bắt đầu với gì?, chọn
Hello World example. - Đối với bạn muốn sử dụng mẫu nào?, chọn
Worker only. - Đối với Ngôn ngữ nào bạn muốn sử dụng?, chọn
TypeScript. - Đối với Do you want to use git for version control?, chọn
Yes. - Đối với Bạn muốn triển khai ứng dụng của mình?, chọn
No(chúng tôi sẽ thực hiện một số thay đổi trước khi triển khai).
- For What would you like to start with?, choose
Hello World example. - For Which template would you like to use?, choose
Worker only. - For Which language do you want to use?, choose
TypeScript. - For Do you want to use git for version control?, choose
Yes. - For Do you want to deploy your application?, choose
No(we will be making some changes before deploying).
- សម្រាប់ តើអ្នកចង់ចាប់ផ្តើមជាមួយអ្វី?, ជ្រើស
Hello World example។ - សម្រាប់គំរូ តើអ្នកចង់ប្រើគំរូណាមួយ?, ជ្រើស
Worker only។ - សម្រាប់ តើអ្នកចង់ប្រើភាសាណាមួយ?, ជ្រើស
TypeScript។ - សម្រាប់ តើអ្នកចង់ប្រើ git សម្រាប់ការគ្រប់គ្រងកំណែ?, ជ្រើស
Yes។ - សម្រាប់ តើអ្នកចង់ដំឡើងកម្មវិធីរបស់អ្នក?, ជ្រើស
No(យើងនឹងធ្វើការផ្លាស់ប្តូរមួយចំនួនមុនពេលដំឡើង) ។
pdf-summarizer:pdf-summarizer directory:pdf-summarizer:cd pdf-summarizer Liên kết liên quan (docs Cloudflare) Related links (Cloudflare docs) តំណពាក់ព័ន្ធ (docs Cloudflare)
2.Đối với Tạo Front-end 2. Create the front-end 2 ។ បានបង្កើត Front-end
Phần «Tạo front-end» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.
Read the "2. Create the front-end" section below — open the official docs link for full screenshots and configuration tabs.
អានផ្នែក «2 ។ បានបង្កើត Front-end» ខាងក្រោម — បើកតំណ docs ផ្លូវការសម្រាប់រូបភាព និង tab កំណត់។
{
"assets": {
"directory": "public"
}
} [assets]
directory = "public" public và thêm một tập tin index.html. Tệp index.html nên chứa mã HTML sau:public directory and add an index.html file. The index.html file should contain the following HTML code:public និងបន្ថែមឯកសារ index.html ។ ឯកសារ index.html នឹងមានលេខកូដដូចខាងក្រោម HTML:<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>PDF Summarizer</title>
<style>
body {
font-family: Arial, sans-serif;
display: flex;
flex-direction: column;
min-height: 100vh;
margin: 0;
background-color: #fefefe;
}
.content {
flex: 1;
display: flex;
justify-content: center;
align-items: center;
}
.upload-container {
background-color: #f0f0f0;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
.upload-button {
background-color: #4caf50;
color: white;
padding: 10px 15px;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
}
.upload-button:hover {
background-color: #45a049;
}
footer {
background-color: #f0f0f0;
color: white;
text-align: center;
padding: 10px;
width: 100%;
}
footer a {
color: #333;
text-decoration: none;
margin: 0 10px;
}
footer a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<div class="content">
<div class="upload-container">
<h2>Upload PDF File</h2>
<form id="uploadForm" onsubmit="return handleSubmit(event)">
<input
type="file"
id="pdfFile"
name="pdfFile"
accept=".pdf"
required
/>
<button type="submit" id="uploadButton" class="upload-button">
Upload
</button>
</form>
</div>
</div>
<footer>
<a
href="https://developers.cloudflare.com/r2/buckets/event-notifications/"
target="_blank"
>R2 Event Notification</a
>
<a
href="https://developers.cloudflare.com/queues/get-started/#3-create-a-queue"
target="_blank"
>Cloudflare Queues</a
>
<a href="https://developers.cloudflare.com/workers-ai/" target="_blank"
>Workers AI</a
>
<a
href="https://github.com/harshil1712/pdf-summarizer-r2-event-notification"
target="_blank"
>GitHub Repo</a
>
</footer>
<script>
handleSubmit = async (event) => {
event.preventDefault();
// Disable the upload button and show a loading message
const uploadButton = document.getElementById("uploadButton");
uploadButton.disabled = true;
uploadButton.textContent = "Uploading...";
// get form data
const formData = new FormData(event.target);
const file = formData.get("pdfFile");
if (file) {
// call /api/upload endpoint and send the file
await fetch("/api/upload", {
method: "POST",
body: formData,
});
event.target.reset();
} else {
console.log("No file selected");
}
uploadButton.disabled = false;
uploadButton.textContent = "Upload";
};
</script>
</body>
</html> npm run dev ⛅️ wrangler 3.80.2
-------------------
⎔ Starting local server...
[wrangler:inf] Ready on http://localhost:8787
╭───────────────────────────╮
│ [b] open a browser │
│ [d] open devtools │
│ [l] turn off local mode │
│ [c] clear console │
│ [x] to exit │
╰───────────────────────────╯ 3 Cái Tải file upload 3. Handle file upload 3 ។ ទាញយកឯកសារ Upload
Phần «Xử lý file upload» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.
Read the "3. Handle file upload" section below — open the official docs link for full screenshots and configuration tabs.
អានផ្នែក «3 ។ ទាញយកឯកសារ Upload» ខាងក្រោម — បើកតំណ docs ផ្លូវការសម្រាប់រូបភាព និង tab កំណត់។
{
"r2_buckets": [
{
"binding": "MY_BUCKET",
"bucket_name": "<R2_BUCKET_NAME>"
}
]
} [[r2_buckets]]
binding = "MY_BUCKET"
bucket_name = "<R2_BUCKET_NAME>" <R2<em>BUCKET</em>NAME> bằng tên của hộp R2 của bạn.<R2<em>BUCKET</em>NAME> with the name of your R2 bucket.<R2<em>BUCKET</em>NAME> ជាមួយនឹងឈ្មោះនៃ R2 របស់អ្នក។src/index.ts. Tệp src/index.ts nên chứa mã sau:src/index.ts file. The src/index.ts file should contain the following code:src/index.ts ។ ឯកសារ src/index.ts នឹងមានលេខកូដដូចខាងក្រោម:export default {
async fetch(request, env, ctx): Promise<Response> {
// Get the pathname from the request
const pathname = new URL(request.url).pathname;
if (pathname === "/api/upload" && request.method === "POST") {
// Get the file from the request
const formData = await request.formData();
const file = formData.get("pdfFile") as File;
// Upload the file to Cloudflare R2
const upload = await env.MY_BUCKET.put(file.name, file);
return new Response("File uploaded successfully", { status: 200 });
}
return new Response("incorrect route", { status: 404 });
},
} satisfies ExportedHandler<Env>; - Kiểm tra xem yêu cầu đó có phải là yêu cầu POST đến điểm cuối
/api/uploadhay không. Nếu có, nó nhận được tệp từ yêu cầu và tải nó lên Cloudflare R2 bằng cách sử dụng Workers API. - Nếu yêu cầu không phải là một yêu cầu POST đến điểm cuối
/api/upload, nó sẽ trả về một câu trả lời 404.
- Check if the request is a POST request to the
/api/uploadendpoint. If it is, it gets the file from the request and uploads it to Cloudflare R2 using the Workers API. - If the request is not a POST request to the
/api/uploadendpoint, it returns a 404 response.
- សូមពិនិត្យមើលប្រសិនបើតម្រូវការនេះគឺជាតម្រូវការ POST ទៅបញ្ចប់
/api/upload។ ប្រសិនបើវាគឺ, វាត្រូវបានទទួលបានឯកសារពីសំណួរនិងផ្ទុកវាទៅ Cloudflare R2 ដោយប្រើ Workers API ។ - ប្រសិនបើទម្រង់នេះមិនជាទម្រង់ POST ទៅ
/api/uploadដំបូងវាត្រូវបានបង្ហាញនូវការឆ្លើយតប 404 ។
request.formData() trong cùng một yêu cầu, bạn có thể gặp lỗi TypeError khi cố gắng access request.body.request.formData() in the same request, you may encounter a TypeError when attempting to access request.body.request.formData() នៅពេលមុននៅក្នុងសំណួរដូចគ្នានេះអ្នកអាចរកឃើញ TypeError នៅពេលដែលអ្នកធ្វើការ access request.body ។request.clone() cho mỗi nỗ lực tiếp theo để access cơ thể của yêu cầu. Hãy nhớ rằng Workers có memory limit of 128 MB per Worker và tải các tệp đặc biệt lớn vào bộ nhớ của Người lao động nhiều lần có thể đạt đến giới hạn này. Để đảm bảo sử dụng bộ nhớ không đạt đến giới hạn này, hãy xem xét sử dụng Streams.request.clone() for each subsequent attempt to access a Request's body. Keep in mind that Workers have a memory limit of 128 MB per Worker and loading particularly large files into a Worker's memory multiple times may reach this limit. To ensure memory usage does not reach this limit, consider using Streams.request.clone() for each subsequent attempt to access a Request's body. Keep in mind that Workers have a memory limit of 128 MB per Worker and loading particularly large files into a Worker's memory multiple times may reach this limit. To ensure memory usage does not reach this limit, consider using Streams.npm run cf-typegen npm run dev Liên kết liên quan (docs Cloudflare) Related links (Cloudflare docs) តំណពាក់ព័ន្ធ (docs Cloudflare)
Bốn Tạo một cái đuôi 4. Create a queue 4 ។ បានបង្កើតកម្រិត
Phần «Tạo queue» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.
Read the "4. Create a queue" section below — open the official docs link for full screenshots and configuration tabs.
អានផ្នែក «4 ។ បានបង្កើតកម្រិត» ខាងក្រោម — បើកតំណ docs ផ្លូវការសម្រាប់រូបភាព និង tab កំណត់។
pdf-summarize để nhận thông báo:pdf-summarize to receive notifications:pdf-summarize ដើម្បីទទួលបានការយល់ដឹង:npx wrangler queues create pdf-summarizer {
"queues": {
"consumers": [
{
"queue": "pdf-summarizer"
}
]
}
} [[queues.consumers]]
queue = "pdf-summarizer" 5 Xử lý thông báo sự kiện 5. Handle event notifications 5 ។ រក្សាសិទ្ធគ្រប់គ្រងប្រវត្តិសាស្រ្ត
Phần «Xử lý event notifications» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.
Read the "5. Handle event notifications" section below — open the official docs link for full screenshots and configuration tabs.
អានផ្នែក «5 ។ រក្សាសិទ្ធគ្រប់គ្រងប្រវត្តិសាស្រ្ត» ខាងក្រោម — បើកតំណ docs ផ្លូវការសម្រាប់រូបភាព និង tab កំណត់។
src/index.ts để thêm trình xử lý Queue:src/index.ts file to add the Queue handler:src/index.ts ដើម្បីបន្ថែមការចែកចាយការចែកចាយ:export default {
async fetch(request, env, ctx): Promise<Response> {
// No changes in the fetch handler
},
async queue(batch, env) {
for (let message of batch.messages) {
console.log(`Processing the file: ${message.body.object.key}`);
}
},
} satisfies ExportedHandler<Env>; - Bộ xử lý
queueđược gọi khi một thông điệp mới được thêm vào hàng đợi. Nó chạy qua các tin nhắn trong lô và ghi lại tên tệp.
- The
queuehandler is called when a new message is added to the queue. It loops through the messages in the batch and logs the name of the file.
- អ្នកគ្រប់គ្រង
queueត្រូវបានសរសេរនៅពេលដែលសេចក្តីអធិប្បាយថ្មីត្រូវបានបន្ថែមទៅក្នុងការសរសេរ។ វាត្រូវបានដំណើរការដោយប្រព័ន្ធផ្សព្វផ្សាយនិងប្រព័ន្ធផ្សព្វផ្សាយនិងប្រព័ន្ធផ្សព្វផ្សាយនិងប្រព័ន្ធផ្សព្វផ្សាយ។
queue không làm gì cả. Trong các bước tiếp theo, bạn sẽ cập nhật trình xử lý queue để trích xuất nội dung văn bản từ PDF, sử dụng Workers AI để tóm tắt nội dung, và sau đó thêm nó vào thùng chứa.queue handler is not doing anything. In the next steps, you will update the queue handler to extract the textual content from the PDF, use Workers AI to summarize the content, and then add it to the bucket.queue មិនធ្វើអ្វីទេ។ នៅក្នុងដំណោះស្រាយបន្ទាប់អ្នកនឹងដំណើរការ queue ដើម្បីបង្វិលសម្ភារៈសម្ភារៈពី PDF, ប្រើ Workers AI ដើម្បីបង្វិលសម្ភារៈនិងបន្ទាប់មកបន្ថែមវាទៅក្នុងកាបូប។Sáu Trích xuất nội dung văn bản từ PDF 6. Extract the textual content from the PDF 6 ។ ការបញ្ចេញសម្ភារៈសម្ភារៈពី PDF
Phần «Extract textual content từ PDF» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.
Read the "6. Extract the textual content from the PDF" section below — open the official docs link for full screenshots and configuration tabs.
អានផ្នែក «6 ។ ការបញ្ចេញសម្ភារៈសម្ភារៈពី PDF» ខាងក្រោម — បើកតំណ docs ផ្លូវការសម្រាប់រូបភាព និង tab កំណត់។
unpdf cung cấp các tiện ích để làm việc với các tệp PDF.unpdf library provides utilities to work with PDF files.unpdf អនុញ្ញាតឱ្យអ្នកធ្វើការជាមួយឯកសារ PDF ។unpdf bằng cách chạy lệnh sau:unpdf library by running the following command:unpdf ដោយធ្វើការបញ្ជាបញ្ជាខាងក្រោមនេះ:npm i unpdf yarn add unpdf pnpm add unpdf bun add unpdf src/index.ts để nhập các mô-đun cần thiết từ thư viện unpdf:src/index.ts file to import the required modules from the unpdf library:src/index.ts ដើម្បីនាំចូលម៉ូឌុលដែលត្រូវការពីសៀវភៅ unpdf:import { extractText, getDocumentProxy } from "unpdf"; queue để trích xuất nội dung văn bản từ PDF:queue handler to extract the textual content from the PDF:queue ដើម្បីកាត់បន្ថយសម្ភារៈសៀវភៅពី PDF:async queue(batch, env) {
for(let message of batch.messages) {
console.log(`Processing file: ${message.body.object.key}`);
// Get the file from the R2 bucket
const file = await env.MY_BUCKET.get(message.body.object.key);
if (!file) {
console.error(`File not found: ${message.body.object.key}`);
continue;
}
// Extract the textual content from the PDF
const buffer = await file.arrayBuffer();
const document = await getDocumentProxy(new Uint8Array(buffer));
const {text} = await extractText(document, {mergePages: true});
console.log(`Extracted text: ${text.substring(0, 100)}...`);
}
} - Bộ xử lý
queuelấy tệp từ thùng R2. - Bộ xử lý
queuetrích xuất nội dung văn bản từ PDF bằng cách sử dụng thư việnunpdf. - Bộ xử lý
queueghi lại nội dung văn bản.
- The
queuehandler gets the file from the R2 bucket. - The
queuehandler extracts the textual content from the PDF using theunpdflibrary. - The
queuehandler logs the textual content.
- អ្នកគ្រប់គ្រង
queueបានទទួលបានឯកសារពីការ R2 ។ - ការដំណើរការ
queueបានបញ្ចេញសម្ភារៈសៀវភៅពី PDF ដោយប្រើសៀវភៅunpdf។ - ការដំណើរការ
queueបានកំណត់សម្ភារៈអត្ថបទ។
Bảy Sử dụng Workers AI để tóm tắt nội dung 7. Use Workers AI to summarize the content 7 ។ ប្រើ Workers AI ដើម្បីកំណត់សម្ភារៈ
Phần «Sử dụng Workers AI to summarize content» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.
Read the "7. Use Workers AI to summarize the content" section below — open the official docs link for full screenshots and configuration tabs.
អានផ្នែក «7 ។ ប្រើ Workers AI ដើម្បីកំណត់សម្ភារៈ» ខាងក្រោម — បើកតំណ docs ផ្លូវការសម្រាប់រូបភាព និង tab កំណត់។
{
"ai": {
"binding": "AI"
}
} [ai]
binding = "AI" npm run cf-typegen src/index.ts để sử dụng Workers AI để tóm tắt nội dung:src/index.ts file to use Workers AI to summarize the content:src/index.ts ដើម្បីប្រើ Workers AI ដើម្បីកំណត់គំនិតនេះ:async queue(batch, env) {
for(let message of batch.messages) {
// Extract the textual content from the PDF
const {text} = await extractText(document, {mergePages: true});
console.log(`Extracted text: ${text.substring(0, 100)}...`);
// Use Workers AI to summarize the content
const result: AiSummarizationOutput = await env.AI.run(
"@cf/facebook/bart-large-cnn",
{
input_text: text,
}
);
const summary = result.summary;
console.log(`Summary: ${summary.substring(0, 100)}...`);
}
} queue bây giờ sử dụng Workers AI để tóm tắt nội dung.queue handler now uses Workers AI to summarize the content.queue ឥឡូវនេះប្រើ Workers AI ដើម្បីកំណត់គំនិត។Tám Thêm tóm tắt vào R2 bucket 8. Add the summary to the R2 bucket 8 ។ បន្ថែមសៀវភៅរបស់អ្នកទៅ R2 bucket
Phần «Thêm summary to R2 bucket» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.
Read the "8. Add the summary to the R2 bucket" section below — open the official docs link for full screenshots and configuration tabs.
អានផ្នែក «8 ។ បន្ថែមសៀវភៅរបស់អ្នកទៅ R2 bucket» ខាងក្រោម — បើកតំណ docs ផ្លូវការសម្រាប់រូបភាព និង tab កំណត់។
src/index.ts để thêm tóm tắt vào hộp R2:src/index.ts file to add the summary to the R2 bucket:src/index.ts ដើម្បីបន្ថែមសៀវភៅសៀវភៅសៀវភៅសៀវភៅ R2:async queue(batch, env) {
for(let message of batch.messages) {
// Extract the textual content from the PDF
// ...
// Use Workers AI to summarize the content
// ...
// Add the summary to the R2 bucket
const upload = await env.MY_BUCKET.put(`${message.body.object.key}-summary.txt`, summary, {
httpMetadata: {
contentType: 'text/plain',
},
});
console.log(`Summary added to the R2 bucket: ${upload.key}`);
}
} Chín Cho phép thông báo sự kiện 9. Enable event notifications 9 ។ អនុញ្ញាតឱ្យប្រសិនបើប្រសិនបើ
Phần «Enable event notifications» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.
Read the "9. Enable event notifications" section below — open the official docs link for full screenshots and configuration tabs.
អានផ្នែក «9 ។ អនុញ្ញាតឱ្យប្រសិនបើប្រសិនបើ» ខាងក្រោម — បើកតំណ docs ផ្លូវការសម្រាប់រូបភាព និង tab កំណត់។
queue của bạn đã sẵn sàng để xử lý các tin nhắn thông báo sự kiện đến. Bạn cần kích hoạt thông báo sự kiện với wrangler r2 bucket notification create command cho thùng chứa của bạn. Lệnh sau đây tạo một thông báo sự kiện cho kiểu sự kiện object-create cho phụ đề pdf:queue handler is ready to handle incoming event notification messages. You need to enable event notifications with the wrangler r2 bucket notification create command for your bucket. The following command creates an event notification for the object-create event type for the pdf suffix:queue របស់អ្នកមានការរចនាឡើងសម្រាប់ការដោះស្រាយជាមួយប្រសិនបើអ្នកទទួលបានប្រសិនបើអ្នកទទួលបានប្រសិនបើអ្នកទទួលបានប្រសិនបើអ្នកទទួលបានប្រសិនបើអ្នកទទួលបានប្រសិនបើអ្នកទទួលបានប្រសិនបើអ្នកទទួលបានប្រសិនបើអ្នកទទួលបានប្រសិនបើអ្នកទទួលបានប្រសិនបើអ្នកទទួលបានប្រសិនបើអ្នកទទួលបានប្រសិនបើអ្នកទទួលបានប្រសិនបើអ្នកទទួលបានប្រសិនបើអ្នកទទួលបានប្រសិនបើអ្នកទទួលបានប្រសិនបើអ្នកទទួលបានប្រសិនបើអ្នកទទួលបានប្រសិនបើអ្នកទទួលបានប្រសិនបើអ្នកទទួលបានប្រសិនបើអ្នកទទួលបានប្រសិនបើអ្នកទទួលបានប្រសិនបើអ្នកទទួល អ្នកត្រូវអនុញ្ញាតឱ្យប្រកាសប្រកាសប្រកាសប្រកាស wrangler r2 bucket notification create command សម្រាប់កាបូបរបស់អ្នក។ ការបញ្ជាក់ដូចខាងក្រោមនឹងបង្កើតការបញ្ជាក់ប្រវត្តិសាស្រ្តសម្រាប់ប្រភេទប្រវត្តិសាស្រ្ត object-create សម្រាប់ការបញ្ជាក់ pdf:npx wrangler r2 bucket notification create <R2_BUCKET_NAME> --event-type object-create --queue pdf-summarizer --suffix "pdf" <R2<em>BUCKET</em>NAME> bằng tên của hộp R2 của bạn.<R2<em>BUCKET</em>NAME> with the name of your R2 bucket.<R2<em>BUCKET</em>NAME> ជាមួយនឹងឈ្មោះនៃ R2 របស់អ្នក។pdf. Khi một tệp mới với phụ lục pdf được tải lên thùng R2, hàng pdf-summarizer được kích hoạt.pdf suffix. When a new file with the pdf suffix is uploaded to the R2 bucket, the pdf-summarizer queue is triggered.pdf ។ នៅពេលដែលឯកសារថ្មីដែលមានការបញ្ចប់ pdf ត្រូវបានទាញយកទៅ R2 bucket, ការបញ្ចប់ pdf-summarizer ត្រូវបានបង្កើតឡើង។Liên kết liên quan (docs Cloudflare) Related links (Cloudflare docs) តំណពាក់ព័ន្ធ (docs Cloudflare)
Mười triển khai công nhân của bạn 10. Deploy your Worker 10 ។ បញ្ចូលការងាររបស់អ្នក
Phần «Triển khai your Worker» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.
Read the "10. Deploy your Worker" section below — open the official docs link for full screenshots and configuration tabs.
អានផ្នែក «10 ។ បញ្ចូលការងាររបស់អ្នក» ខាងក្រោម — បើកតំណ docs ផ្លូវការសម្រាប់រូបភាព និង tab កំណត់។
npx wrangler deploy wrangler deploy, sao chép URL. Đây là URL của ứng dụng đã triển khai của bạn.wrangler deploy command, copy the URL. This is the URL of your deployed application.wrangler deploy ចម្លង URL ។ នេះគឺជា URL នៃកម្មវិធីដែលអ្នកបានដំឡើង។Liên kết liên quan (docs Cloudflare) Related links (Cloudflare docs) តំណពាក់ព័ន្ធ (docs Cloudflare)
Mười một thử nghiệm 11. Test 11 ។ ការធ្វើតេស្ត
Phần «Test» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.
Read the "11. Test" section below — open the official docs link for full screenshots and configuration tabs.
អានផ្នែក «11 ។ ការធ្វើតេស្ត» ខាងក្រោម — បើកតំណ docs ផ្លូវការសម្រាប់រូបភាព និង tab កំណត់។
npx wrangler tail Liên kết liên quan (docs Cloudflare) Related links (Cloudflare docs) តំណពាក់ព័ន្ធ (docs Cloudflare)
Kết luận Conclusion លទ្ធផល
Phần «Kết luận» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.
Read the "Conclusion" section below — open the official docs link for full screenshots and configuration tabs.
អានផ្នែក «លទ្ធផល» ខាងក្រោម — បើកតំណ docs ផ្លូវការសម្រាប់រូបភាព និង tab កំណត់។
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"item":{"@id":"/directory/","name":"Directory"}},{"@type":"ListItem","position":2,"item":{"@id":"/r2/","name":"R2"}},{"@type":"ListItem","position":3,"item":{"@id":"/r2/tutorials/","name":"Tutorials"}},{"@type":"ListItem","position":4,"item":{"@id":"/r2/tutorials/summarize-pdf/","name":"Use event notification to summarize PDF files on upload"}}]} Xem bản đầy đủ trên developers.cloudflare.com (ảnh, tab cấu hình). View the full guide on developers.cloudflare.com (images, config tabs). មើលមគ្គុទ្ទេសក៍ពេញលើ developers.cloudflare.com (រូបភាព, tab កំណត់)។
Tài liệu gốc ↗ Official docs ↗ ឯកសារផ្លូវការ ↗