Tutorial Tutorial Tutorial Developer Platform Developer Platform Developer Platform ~88 phút ~88 min ~88 នាទី Đồng bộ 2026-06-10 Synced 2026-06-10 ធ្វើសមកាល 2026-06-10

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 កំណត់។

Mở section docs gốc ↗ Open source section ↗ បើកផ្នែក docs ផ្លូវការ ↗
Trong hướng dẫn này, bạn sẽ học cách sử dụng event notifications để xử lý tệp PDF khi nó được tải lên bucket R2. Bạn sẽ sử dụng Workers AI để tóm tắt PDF và lưu tóm tắt dưới dạng tệp văn bản trong cùng một thùng chứa.
In this tutorial, you will learn how to 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.
ក្នុងការបណ្តុះបណ្តាលនេះអ្នកនឹងរៀនពីរបៀបប្រើ event notifications ដើម្បីដំណើរការឯកសារ PDF នៅពេលដែលវាត្រូវបានផ្ទុកទៅ R2 ។ អ្នកនឹងប្រើ Workers AI ដើម្បីបញ្ចប់ PDF និងផ្ទុកបញ្ចប់ជាឯកសារសៀវភៅនៅក្នុងកាបូបដូចគ្នា។

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ở section docs gốc ↗ Open source section ↗ បើកផ្នែក docs ផ្លូវការ ↗
Để tiếp tục, bạn sẽ cần:
To continue, you will need:
ដើម្បីដំណើរការអ្នកនឹងត្រូវការ:
Node.js Trình quản lý phiên bản
Node.js version manager
Node.js អ្នកគ្រប់គ្រងកំណែ
Sử dụng trình quản lý phiên bản nút như Volta ↗ hoặc nvm ↗ để tránh các vấn đề quyền và thay đổi các phiên bản Node.js. Wrangler, được thảo luận sau trong hướng dẫn này, yêu cầu một phiên bản nút của 16.17.0 hoặc mới hơn.
Use a Node version manager like Volta ↗ ornvm ↗ to avoid permission issues and change Node.js versions. Wrangler, discussed later in this guide, requires a Node version of 16.17.0 or later.
ប្រើកម្មវិធីគ្រប់គ្រងកំណែ Node ដូចជា Volta ↗ ឬ nvm ↗ ដើម្បីជួសជុលបញ្ហាការអនុញ្ញាតនិងផ្លាស់ប្តូរកំណែ Node.js ។ Wrangler ដែលត្រូវបានពិភាក្សាបន្ទាប់មកនៅក្នុងវគ្គសិក្សានេះត្រូវការកំណែ Node នៃ 16.17.0 ឬបន្ទាប់មក។

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 កំណត់។

Mở section docs gốc ↗ Open source section ↗ បើកផ្នែក docs ផ្លូវការ ↗
Bạn sẽ tạo một dự án Công nhân mới sẽ sử dụng Static Assets để phục vụ phần trước của ứng dụng của bạn. Một người dùng có thể tải lên một tệp PDF bằng cách sử dụng front-end này, sau đó sẽ được xử lý bởi Worker của bạn.
You will 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.
អ្នកនឹងបង្កើតគម្រោងបុគ្គលិកថ្មីដែលនឹងប្រើ Static Assets ដើម្បីបម្រើផ្នែកខាងមុខនៃកម្មវិធីរបស់អ្នក។ អ្នកប្រើប្រាស់អាចទាញយកឯកសារ PDF ដោយប្រើ front-end នេះដែលនឹងត្រូវបានដំណើរការដោយ Worker របស់អ្នក។
Tạo dự án Worker mới bằng cách chạy các lệnh sau:
Create a new Worker project by running the following commands:
បានបង្កើតគម្រោងការងារថ្មីដោយដំណើរការគោលបំណងដូចខាងក្រោម:
Mã sản phẩm: npm yarn pnpm
npm yarn pnpm
លក្ខណៈពិសេស NPM
text
npm create cloudflare@latest -- pdf-summarizer
text
yarn create cloudflare pdf-summarizer
text
pnpm create cloudflare@latest pdf-summarizer
Để cài đặt, hãy chọn các tùy chọn sau:
For setup, select the following options:
សម្រាប់ការដំឡើងអ្នកជ្រើសរើសជម្រើសខាងក្រោម:
  • Đố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 (យើងនឹងធ្វើការផ្លាស់ប្តូរមួយចំនួនមុនពេលដំឡើង) ។
Chuyển sang thư mục pdf-summarizer:
Navigate to the pdf-summarizer directory:
សូមចូលទៅក្នុងប្រព័ន្ធប្រតិបត្តិការ pdf-summarizer:
text
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 កំណត់។

Mở section docs gốc ↗ Open source section ↗ បើកផ្នែក docs ផ្លូវការ ↗
Sử dụng Static Assets, bạn có thể phục vụ phần trước của ứng dụng từ Worker của bạn. Để sử dụng Static Assets, bạn cần thêm các liên kết cần thiết vào tệp Wrangler của bạn.
Using Static Assets, you can serve the front-end of your application from your Worker. To use Static Assets, you need to add the required bindings to your Wrangler file.
ដោយប្រើឧបករណ៍ Static Assets អ្នកអាចផ្គត់ផ្គង់ផ្នែកខាងមុខនៃកម្មវិធីរបស់អ្នកពី Worker របស់អ្នក។ ប្រសិនបើអ្នកចង់ប្រើឧបករណ៍ Static Assets អ្នកគួរតែបន្ថែមការភ្ជាប់ដែលត្រូវការទៅក្នុងឯកសារ Wrangler របស់អ្នក។
JSONC
JSONC
JSONC
text
{

  "assets": {

    "directory": "public"

  }

}
TOML
TOML
TOML
text
[assets]

directory = "public"
Tiếp theo, tạo một thư mục public và thêm một tập tin index.html. Tệp index.html nên chứa mã HTML sau:
Next, create a public directory and add an index.html file. The index.html file should contain the following HTML code:
បន្ទាប់មកបង្កើតឯកសារ public និងបន្ថែមឯកសារ index.html ។ ឯកសារ index.html នឹងមានលេខកូដដូចខាងក្រោម HTML:
Chọn để xem mã HTML
Select to view the HTML code
ជ្រើសដើម្បីមើលលេខកូដ HTML
text
<!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>
Để xem phần đầu của ứng dụng của bạn, hãy chạy lệnh sau và điều hướng đến URL hiển thị trong thiết bị đầu cuối:
To view the front-end of your application, run the following command and navigate to the URL displayed in the terminal:
ប្រសិនបើអ្នកចង់មើលអេឡិចត្រូនិចនៃកម្មវិធីរបស់អ្នក, សូមដំណើរការជម្រើសខាងក្រោមនិងដំណើរការទៅ URL ដែលបានបង្ហាញនៅក្នុងឧបករណ៍បញ្ចប់:
Cửa sổ Terminal
Terminal window
បង្វិល Terminal
text
npm run dev
text
⛅️ 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              │

╰───────────────────────────╯
Khi bạn mở URL trong trình duyệt của bạn, bạn sẽ thấy rằng có một tập tin tải lên form. Nếu bạn cố gắng tải lên một tệp, bạn sẽ nhận thấy rằng tệp không được tải lên máy chủ. Điều này là do front-end không được kết nối với back-end. Trong bước tiếp theo, bạn sẽ cập nhật Worker của bạn sẽ xử lý các tập tin tải lên.
When you open the URL in your browser, you will see that there is a file upload form. If you try uploading a file, you will notice that the file is not uploaded to the server. This is because the front-end is not connected to the back-end. In the next step, you will update your Worker that will handle the file upload.
នៅពេលដែលអ្នកបើក URL នៅលើបណ្តាញរបស់អ្នកអ្នកនឹងមើលឃើញថាមានឯកសារទាញយក form ។ ប្រសិនបើអ្នកធ្វើការទាញយកឯកសារអ្នកនឹងរកឃើញថាឯកសារនេះមិនត្រូវបានទាញយកទៅលើបណ្តាញ។ ដូច្នេះវាគឺជាការពិតប្រាកដថាអេឡិចត្រូនិនេះមិនត្រូវបានបណ្តុះបណ្តាលជាមួយអេឡិចត្រូនិខាងក្រោយ។ នៅក្នុងដំណោះស្រាយបន្ទាប់អ្នកនឹងធ្វើឱ្យប្រសើរឡើង Worker របស់អ្នកដែលនឹងគ្រប់គ្រងការទាញយកឯកសារ។

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 កំណត់។

Mở section docs gốc ↗ Open source section ↗ បើកផ្នែក docs ផ្លូវការ ↗
Để xử lý các tập tin tải lên, trước tiên bạn sẽ cần phải thêm R2 ràng buộc. Trong tập tin Wrangler, hãy thêm mã sau:
To handle the file upload, you will first need to add the R2 binding. In the Wrangler file, add the following code:
ដើម្បីដោះស្រាយការផ្ទុកឯកសារអ្នកនឹងត្រូវការបន្ថែម R2 ការបណ្តុះបណ្តាល។ ក្នុងឯកសារ Wrangler បន្ថែមលេខកូដដូចខាងក្រោម:
JSONC
JSONC
JSONC
text
{

  "r2_buckets": [

    {

      "binding": "MY_BUCKET",

      "bucket_name": "<R2_BUCKET_NAME>"

    }

  ]

}
TOML
TOML
TOML
text
[[r2_buckets]]

binding = "MY_BUCKET"

bucket_name = "<R2_BUCKET_NAME>"
Thay thế <R2<em>BUCKET</em>NAME> bằng tên của hộp R2 của bạn.
Replace <R2<em>BUCKET</em>NAME> with the name of your R2 bucket.
សូមផ្លាស់ប្តូរ <R2<em>BUCKET</em>NAME> ជាមួយនឹងឈ្មោះនៃ R2 របស់អ្នក។
Sau đó, cập nhật tập tin src/index.ts. Tệp src/index.ts nên chứa mã sau:
Next, update the src/index.ts file. The src/index.ts file should contain the following code:
បន្ទាប់មកទាញយកឯកសារ src/index.ts ។ ឯកសារ src/index.ts នឹងមានលេខកូដដូចខាងក្រោម:
Trang chủ / index.ts
src/index.ts
អាសយដ្ឋាន: src / index.ts
text
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>;
Mã trên làm như sau:
The above code does the following:
លេខកូដខាងលើធ្វើដូចខាងក្រោម:
  • Kiểm tra xem yêu cầu đó có phải là yêu cầu POST đến điểm cuối /api/upload hay 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/upload endpoint. 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/upload endpoint, it returns a 404 response.
  • សូមពិនិត្យមើលប្រសិនបើតម្រូវការនេះគឺជាតម្រូវការ POST ទៅបញ្ចប់ /api/upload ។ ប្រសិនបើវាគឺ, វាត្រូវបានទទួលបានឯកសារពីសំណួរនិងផ្ទុកវាទៅ Cloudflare R2 ដោយប្រើ Workers API ។
  • ប្រសិនបើទម្រង់នេះមិនជាទម្រង់ POST ទៅ /api/upload ដំបូងវាត្រូវបានបង្ហាញនូវការឆ្លើយតប 404 ។
Vì mã Worker được viết bằng TypeScript, bạn nên chạy lệnh sau để thêm các định nghĩa kiểu cần thiết. Mặc dù điều này không bắt buộc, nó sẽ giúp bạn tránh những sai lầm.
Since the Worker code is written in TypeScript, you should run the following command to add the necessary type definitions. While this is not required, it will help you avoid errors.
ដោយសារតែកូដ Worker ត្រូវបានសរសេរនៅក្នុង TypeScript អ្នកគួរតែធ្វើការបញ្ជាបញ្ជាខាងក្រោមដើម្បីបន្ថែមបញ្ជាក់ប្រភេទដែលត្រូវការ។ ទោះបីជាវាមិនចាំបាច់ទេប៉ុន្តែវានឹងជួយអ្នកក្នុងការកាត់បន្ថយអារម្មណ៍របស់អ្នក។
Ngăn chặn các lỗi tiềm năng khi truy cập request.body
Prevent potential errors when accessing request.body
ការពារប្រសិនបើមានប្រសិនបើមានប្រសិនបើមានប្រសិនបើមានប្រសិនបើមានប្រសិនបើមានប្រសិនបើមានប្រសិនបើមានប្រសិនបើមានប្រសិនបើមានប្រសិនបើមានប្រសិនបើមានប្រសិនបើមានប្រសិនបើមានប្រសិនបើ
Cơ thể của một Request ↗ chỉ có thể được truy cập một lần. Nếu trước đây bạn đã sử dụng 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.
The body of a Request ↗ can only be accessed once. If you previously used request.formData() in the same request, you may encounter a TypeError when attempting to access request.body.
ទិន្នន័យនៃ Request ↗ មានតែមួយដង។ ប្រសិនបើអ្នកបានប្រើ request.formData() នៅពេលមុននៅក្នុងសំណួរដូចគ្នានេះអ្នកអាចរកឃើញ TypeError នៅពេលដែលអ្នកធ្វើការ access request.body ។
Để tránh các lỗi, hãy tạo một bản sao đối tượng yêu cầu với 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.
To avoid errors, create a clone of the Request object with 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.
To avoid errors, create a clone of the Request object with 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.
Cửa sổ Terminal
Terminal window
បង្វិល Terminal
text
npm run cf-typegen
Bạn có thể khởi động lại máy chủ nhà phát triển để kiểm tra các thay đổi:
You can restart the developer server to test the changes:
អ្នកអាចបើកដំណើរការបណ្តាញអ្នកអភិវឌ្ឍន៍ដើម្បីធ្វើតេស្តការផ្លាស់ប្តូរ:
Cửa sổ Terminal
Terminal window
បង្វិល Terminal
text
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 កំណត់។

Mở section docs gốc ↗ Open source section ↗ បើកផ្នែក docs ផ្លូវការ ↗
Thông báo sự kiện ghi lại các thay đổi đối với dữ liệu trong hộp R2 của bạn. Bạn sẽ cần phải tạo một hàng đợi mới pdf-summarize để nhận thông báo:
Event notifications capture changes to data in your R2 bucket. You will need to create a new queue pdf-summarize to receive notifications:
ការប្រកាសប្រកាសប្រកាសប្រកាសប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធ។ អ្នកនឹងត្រូវការបង្កើតកម្រិតថ្មី pdf-summarize ដើម្បីទទួលបានការយល់ដឹង:
Cửa sổ Terminal
Terminal window
បង្វិល Terminal
text
npx wrangler queues create pdf-summarizer
Thêm liên kết vào tệp Wrangler:
Add the binding to the Wrangler file:
បន្ថែមការបណ្តុះបណ្តាលទៅឯកសារ Wrangler:
JSONC
JSONC
JSONC
text
{

  "queues": {

    "consumers": [

      {

        "queue": "pdf-summarizer"

      }

    ]

  }

}
TOML
TOML
TOML
text
[[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 កំណត់។

Mở section docs gốc ↗ Open source section ↗ បើកផ្នែក docs ផ្លូវការ ↗
Bây giờ bạn có hàng đợi để nhận thông báo sự kiện, bạn cần cập nhật Nhân viên để xử lý thông báo sự kiện. Bạn sẽ cần phải thêm một trình xử lý Queue sẽ 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 đó lưu nó vào hộp R2.
Now that you have a queue to receive event notifications, you need to update the Worker to handle the event notifications. You will need to add a Queue handler that will extract the textual content from the PDF, use Workers AI to summarize the content, and then save it in the R2 bucket.
ឥឡូវនេះដែលអ្នកមានការរក្សាទុកដើម្បីទទួលបានការប្រកាសប្រកាសប្រកាសប្រកាសប្រព័ន្ធប្រតិបត្តិការ, អ្នកត្រូវការធ្វើឱ្យប្រកាសប្រកាសប្រព័ន្ធប្រតិបត្តិការប្រព័ន្ធប្រតិបត្តិការប្រព័ន្ធប្រតិបត្តិការប្រព័ន្ធប្រតិបត្តិការប្រព័ន្ធប្រតិបត្តិការប្រព័ន្ធប្រតិបត្តិការប្រព័ន្ធប្រតិបត្តិការប្រព័ន្ធប្រតិបត្តិការប្រព័ន្ធប្រតិបត្តិការប្រព័ន្ធប្រតិបត្តិការប្រព័ន្ធប្រតិបត្តិការប្រព័ន្ធប្រតិបត្តិការ. អ្នកនឹងត្រូវការបន្ថែមអ្នកគ្រប់គ្រងកំណត់កំណត់កំណត់កំណត់កំណត់កំណត់កំណត់កំណត់កំណត់កំណត់កំណត់កំណត់កំណត់កំណត់កំណត់កំណត់កំណត់កំណត់កំណត់កំណត់កំណត់កំណត់កំណត់កំណត់កំណត់កំណត់កំណត់កំណត់កំណត់កំណត់កំណត់កំណត់កំណត់កំណត់កំណត់កំណត់កំណត់កំណត់កំណត់កំណត់កំណត់កំណត់កំណត់កំណត់កំណត់កំណត់ R2 ។
Cập nhật tệp src/index.ts để thêm trình xử lý Queue:
Update the src/index.ts file to add the Queue handler:
ទាញយកឯកសារ src/index.ts ដើម្បីបន្ថែមការចែកចាយការចែកចាយ:
Trang chủ / index.ts
src/index.ts
អាសយដ្ឋាន: src / index.ts
text
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>;
Mã trên làm như sau:
The above code does the following:
លេខកូដខាងលើធ្វើដូចខាងក្រោម:
  • 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 queue handler 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 ត្រូវបានសរសេរនៅពេលដែលសេចក្តីអធិប្បាយថ្មីត្រូវបានបន្ថែមទៅក្នុងការសរសេរ។ វាត្រូវបានដំណើរការដោយប្រព័ន្ធផ្សព្វផ្សាយនិងប្រព័ន្ធផ្សព្វផ្សាយនិងប្រព័ន្ធផ្សព្វផ្សាយនិងប្រព័ន្ធផ្សព្វផ្សាយ។
Hiện tại, người quản lý 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.
For now the 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 កំណត់។

Mở section docs gốc ↗ Open source section ↗ បើកផ្នែក docs ផ្លូវការ ↗
Để trích xuất nội dung văn bản từ PDF, Công nhân sẽ sử dụng thư viện unpdf ↗. Thư viện unpdf cung cấp các tiện ích để làm việc với các tệp PDF.
To extract the textual content from the PDF, the Worker will use the unpdf ↗ library. The unpdf library provides utilities to work with PDF files.
ដើម្បីទាញយកសម្ភារៈសៀវភៅពីឯកសារ PDF អ្នកធ្វើការនឹងប្រើសៀវភៅ unpdf ↗ ។ សៀវភៅ unpdf អនុញ្ញាតឱ្យអ្នកធ្វើការជាមួយឯកសារ PDF ។
Cài đặt thư viện unpdf bằng cách chạy lệnh sau:
Install the unpdf library by running the following command:
ទាញយកប្រព័ន្ធប្រតិបត្តិការ unpdf ដោយធ្វើការបញ្ជាបញ្ជាខាងក្រោមនេះ:
npm yarn pnpm bun
npm yarn pnpm bun
បងបង បង បង បង បង បង បង បង បង
text
npm i unpdf
text
yarn add unpdf
text
pnpm add unpdf
text
bun add unpdf
Cập nhật tệp src/index.ts để nhập các mô-đun cần thiết từ thư viện unpdf:
Update the src/index.ts file to import the required modules from the unpdf library:
ការបច្ចុប្បន្នភាពឯកសារ src/index.ts ដើម្បីនាំចូលម៉ូឌុលដែលត្រូវការពីសៀវភៅ unpdf:
Trang chủ / index.ts
src/index.ts
អាសយដ្ឋាន: src / index.ts
text
import { extractText, getDocumentProxy } from "unpdf";
Tiếp theo, cập nhật trình xử lý queue để trích xuất nội dung văn bản từ PDF:
Next, update the queue handler to extract the textual content from the PDF:
បន្ទាប់មកធ្វើដំណើរការ queue ដើម្បីកាត់បន្ថយសម្ភារៈសៀវភៅពី PDF:
Trang chủ / index.ts
src/index.ts
អាសយដ្ឋាន: src / index.ts
text
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)}...`);

    }

}
Mã trên làm như sau:
The above code does the following:
លេខកូដខាងលើធ្វើដូចខាងក្រោម:
  • Bộ xử lý queue lấy tệp từ thùng R2.
  • Bộ xử lý queue trích xuất nội dung văn bản từ PDF bằng cách sử dụng thư viện unpdf.
  • Bộ xử lý queue ghi lại nội dung văn bản.
  • The queue handler gets the file from the R2 bucket.
  • The queue handler extracts the textual content from the PDF using the unpdf library.
  • The queue handler 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 កំណត់។

Mở section docs gốc ↗ Open source section ↗ បើកផ្នែក docs ផ្លូវការ ↗
Để sử dụng Workers AI, bạn sẽ cần phải thêm kết nối Workers AI vào tệp Wrangler. Tệp Wrangler nên chứa mã sau:
To use Workers AI, you will need to add the Workers AI binding to the Wrangler file. The Wrangler file should contain the following code:
ដើម្បីប្រើ Workers AI, អ្នកនឹងត្រូវបន្ថែម Workers AI ការភ្ជាប់ទៅនឹងឯកសារ Wrangler ។ ឯកសារ Wrangler នឹងមានលេខកូដដូចខាងក្រោម:
JSONC
JSONC
JSONC
text
{

  "ai": {

    "binding": "AI"

  }

}
TOML
TOML
TOML
text
[ai]

binding = "AI"
Thực hiện lệnh sau đây để thêm định nghĩa kiểu AI:
Execute the following command to add the AI type definition:
សូមអនុវត្តជម្រើសខាងក្រោមដើម្បីបន្ថែមការបញ្ជាក់ប្រភេទ AI:
Cửa sổ Terminal
Terminal window
បង្វិល Terminal
text
npm run cf-typegen
Cập nhật tệp src/index.ts để sử dụng Workers AI để tóm tắt nội dung:
Update the src/index.ts file to use Workers AI to summarize the content:
ការបច្ចុប្បន្នភាពឯកសារ src/index.ts ដើម្បីប្រើ Workers AI ដើម្បីកំណត់គំនិតនេះ:
Trang chủ / index.ts
src/index.ts
អាសយដ្ឋាន: src / index.ts
text
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)}...`);

  }

}
Bộ xử lý queue bây giờ sử dụng Workers AI để tóm tắt nội dung.
The 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 កំណត់។

Mở section docs gốc ↗ Open source section ↗ បើកផ្នែក docs ផ្លូវការ ↗
Bây giờ bạn đã có tóm tắt, bạn cần thêm nó vào hộp R2. Cập nhật tệp src/index.ts để thêm tóm tắt vào hộp R2:
Now that you have the summary, you need to add it to the R2 bucket. Update the src/index.ts file to add the summary to the R2 bucket:
ឥឡូវនេះដែលអ្នកមានសៀវភៅសៀវភៅនេះអ្នកត្រូវបន្ថែមវាទៅ R2 កាបូប។ ការធ្វើឱ្យប្រសើរឡើងឯកសារ src/index.ts ដើម្បីបន្ថែមសៀវភៅសៀវភៅសៀវភៅសៀវភៅ R2:
Trang chủ / index.ts
src/index.ts
អាសយដ្ឋាន: src / index.ts
text
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}`);

  }

}
Bộ xử lý hàng đợi bây giờ thêm tóm tắt vào thùng R2 dưới dạng tệp văn bản.
The queue handler now adds the summary to the R2 bucket as a text file.
អ្នកគ្រប់គ្រងបន្ទប់នេះបន្ថែមសៀវភៅសៀវភៅសៀវភៅសៀវភៅសៀវភៅសៀវភៅសៀវភៅសៀវភៅសៀវភៅសៀវភៅសៀវភៅសៀវភៅសៀវភៅសៀវភៅសៀវភៅសៀវភៅសៀវភៅសៀវភៅសៀវភៅសៀវភៅសៀវភៅសៀវភៅសៀវភៅសៀវភៅសៀវភៅសៀវភៅសៀវភៅសៀវភៅសៀវភៅសៀវភៅសៀវភៅសៀវភៅសៀវភៅសៀវភៅសៀវភៅសៀវភៅសៀវភៅសៀវភៅសៀវភៅសៀវភៅសៀវភៅ

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 កំណត់។

Mở section docs gốc ↗ Open source section ↗ បើកផ្នែក docs ផ្លូវការ ↗
Bộ xử lý 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:
Your 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:
Cửa sổ Terminal
Terminal window
បង្វិល Terminal
text
npx wrangler r2 bucket notification create <R2_BUCKET_NAME> --event-type object-create --queue pdf-summarizer --suffix "pdf"
Thay thế <R2<em>BUCKET</em>NAME> bằng tên của hộp R2 của bạn.
Replace <R2<em>BUCKET</em>NAME> with the name of your R2 bucket.
សូមផ្លាស់ប្តូរ <R2<em>BUCKET</em>NAME> ជាមួយនឹងឈ្មោះនៃ R2 របស់អ្នក។
Một thông báo sự kiện được tạo cho phụ đề 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.
An event notification is created for the 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 កំណត់។

Mở section docs gốc ↗ Open source section ↗ បើកផ្នែក docs ផ្លូវការ ↗
Để triển khai Worker của bạn, hãy chạy lệnh wrangler deploy:
To deploy your Worker, run the wrangler deploy command:
ដើម្បីដំឡើង Worker របស់អ្នក, ការដំឡើង wrangler deploy ឧបករណ៍:
Cửa sổ Terminal
Terminal window
បង្វិល Terminal
text
npx wrangler deploy
Trong đầu ra của lệnh wrangler deploy, sao chép URL. Đây là URL của ứng dụng đã triển khai của bạn.
In the output of the 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 កំណត់។

Mở section docs gốc ↗ Open source section ↗ បើកផ្នែក docs ផ្លូវការ ↗
Để kiểm tra ứng dụng, hãy điều hướng đến URL của ứng dụng đã triển khai của bạn và tải lên một tệp PDF. Ngoài ra, bạn có thể sử dụng Cloudflare dashboard ↗ để tải lên tệp PDF.
To test the application, navigate to the URL of your deployed application and upload a PDF file. Alternatively, you can use the Cloudflare dashboard ↗ to upload a PDF file.
ដើម្បីធ្វើតេស្តកម្មវិធីរបស់អ្នក, សូមដំណើរការទៅ URL នៃកម្មវិធីដែលអ្នកដំឡើងហើយទាញយកឯកសារ PDF ។ លើសពីនេះអ្នកអាចប្រើ Cloudflare dashboard ↗ ដើម្បីទាញយកឯកសារ PDF ។
Để xem các nhật ký, bạn có thể sử dụng lệnh wrangler tail.
To view the logs, you can use the wrangler tail command.
ប្រសិនបើអ្នកចង់មើលកំណត់ហេតុបណ្ដាញរបស់អ្នក, អ្នកអាចប្រើការបញ្ជា wrangler tail ។
Cửa sổ Terminal
Terminal window
បង្វិល Terminal
text
npx wrangler tail
Bạn sẽ thấy các nhật ký trong terminal của bạn. Bạn cũng có thể điều hướng đến bảng điều khiển Cloudflare và xem các nhật ký trong phần nhật ký Workers.
You will see the logs in your terminal. You can also navigate to the Cloudflare dashboard and view the logs in the Workers Logs section.
អ្នកនឹងមើលកំណត់ហេតុបណ្ដាញនៅក្នុងការបញ្ចប់របស់អ្នក។ អ្នកក៏អាចដំណើរការទៅក្នុងប្រព័ន្ធប្រតិបត្តិការ Cloudflare និងមើលប្រព័ន្ធប្រតិបត្តិការនៅក្នុងប្រព័ន្ធប្រតិបត្តិការ Workers ។
Nếu bạn kiểm tra hộp R2, bạn sẽ thấy tệp tóm tắt.
If you check your R2 bucket, you will see the summary file.
ប្រសិនបើអ្នកត្រួតពិនិត្យគំរូ R2 របស់អ្នកអ្នកនឹងមើលឯកសារបញ្ជី។

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 កំណត់។

Mở section docs gốc ↗ Open source section ↗ បើកផ្នែក docs ផ្លូវការ ↗
Trong hướng dẫn này, bạn đã học cách sử dụng thông báo sự kiện R2 để xử lý một đối tượng khi tải lên. Bạn đã tạo một ứng dụng để tải lên một tệp PDF, và tạo ra một người lao động tiêu dùng tạo ra một tóm tắt của tệp PDF. Bạn cũng đã học cách sử dụng Workers AI để tóm tắt nội dung của tệp PDF, và tải tóm tắt lên hộp R2.
In this tutorial, you learned how to use R2 event notifications to process an object on upload. You created an application to upload a PDF file, and created a consumer Worker that creates a summary of the PDF file. You also learned how to use Workers AI to summarize the content of the PDF file, and upload the summary to the R2 bucket.
ក្នុងការបណ្តុះបណ្តាលនេះអ្នកបានដឹងពីរបៀបដើម្បីប្រើការប្រកាស R2 ដើម្បីដំណើរការអេក្រង់នៅលើការផ្ទុក។ អ្នកបានបង្កើតកម្មវិធីដើម្បីទាញយកឯកសារ PDF ហើយអ្នកបានបង្កើតកម្មវិធី Consumer Worker ដែលបង្កើតសៀវភៅអំពីឯកសារ PDF ។ អ្នកក៏បានរៀនពីរបៀបប្រើ Workers AI ដើម្បីបញ្ជាក់សម្ភារៈនៃឯកសារ PDF និងទាញយកសម្ភារៈបញ្ជាក់ទៅ R2 ។
Bạn có thể sử dụng cách tiếp cận tương tự để xử lý các loại tệp khác, chẳng hạn như images, video và tệp âm thanh. Bạn cũng có thể sử dụng cùng một cách tiếp cận để xử lý các loại sự kiện khác, chẳng hạn như xóa đối tượng và cập nhật đối tượng.
You can use the same approach to process other types of files, such as images, videos, and audio files. You can also use the same approach to process other types of events, such as object deletion, and object update.
អ្នកអាចប្រើវិធីសាស្រ្តដូច្នេះដើម្បីដំណើរការប្រភេទឯកសារផ្សេងទៀតដូចជា images, រូបភាពនិងឯកសារអូឌីយ៉ូ។ អ្នកអាចប្រើវិធីសាស្រ្តដូចគ្នានេះដើម្បីដំណើរការប្រភេទផ្សេងទៀតនៃព្រឹត្តិការណ៍ដូចជាការចែកចាយប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធប្រព័ន្ធ។
Nếu bạn muốn xem mã cho hướng dẫn này, bạn có thể tìm thấy nó trên GitHub ↗.
If you want to view the code for this tutorial, you can find it on GitHub ↗.
ប្រសិនបើអ្នកចង់មើលកូដសម្រាប់បច្ចុប្បន្ននេះអ្នកអាចរកឃើញវានៅ GitHub ↗ ។
json
{"@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 ↗ ឯកសារផ្លូវការ ↗