ROOM64 / KNOWLEDGE / NOCODB

Convert Attachments to URLs

Convert attachment fields into comma-separated URL lists for integration with external services

อ่านต้นฉบับที่ NocoDB Official Docs ↗
เอกสารอ้างอิงภาษาอังกฤษเนื้อหาจากเอกสาร NocoDB คงรายละเอียดและโค้ดตามต้นฉบับ · ต้นฉบับอัปเดต 2026-09-25 ชื่อเมนูและฟีเจอร์ที่ใช้ได้ขึ้นอยู่กับเวอร์ชันและรุ่นที่ทีมใช้งาน

Workflows · ระบบอัตโนมัติและ Scripts · Convert Attachments to URLs

← Examples

สารบัญในหน้านี้

Convert attachment fields into comma-separated URL lists for integration with external services

Overview

The attachments-to-URLs script processes attachment fields in your table and converts them into comma-separated URL strings. It is particularly useful when you need to send attachment URLs to third-party integration services that expect URL strings rather than attachment objects.

/**
 * Convert attachments to URLs
 *
 * Outputs comma-separated URLs for all attachments and writes them to another field for each record.
 * Can be used for sending URLs to third-party integration services.
 */

// Script configuration - allows users to select table, view, and fields
const config = input.config({
  title: '📎 Convert attachments to URLs',
  description: 'Output comma-separated URLs for all attachments and write to another field for each record. Can be used for sending URLs to third-party integration services.',
  items: [
    input.config.table('selectedTable', {
      label: 'Table',
      description: 'Select a table with records that have attachments you want URLs for',
    }),
    input.config.field('selectedField', {
      label: 'Attachment field from the selected table',
      parentTable: 'selectedTable',
      description: 'Select the attachment field from the table above you want URLs for'
    }),
    input.config.view('selectedView', {
      label: 'View from the selected table',
      parentTable: 'selectedTable',
    }),
    input.config.field('fieldToEdit', {
      label: 'Field to output the attachment URLs to',
      parentTable: 'selectedTable',
      description: 'A long text field is recommended. A comma-separated list of URLs will be generated here'
    })
  ]
});

// Assign selections to variables for the script
const selectedTable = config.selectedTable;
const selectedField = config.selectedField;
const selectedView = config.selectedView;
const fieldToEdit = config.fieldToEdit;

/**
 * Main function to convert attachments to URLs
 */
async function convertAttachmentsToUrls() {
  // Verify the selected field is an attachment field
  if (selectedField.type !== UITypes.Attachment) {
    output.text(`"${selectedField.name}" is not an attachment field. Run the script again with an attachment field.`, 'error');
    return;
  }

  // Load records from the selected view
  const query = await selectedView.selectRecordsAsync({
    fields: [selectedField]
  });

  // Get all records
  const records = query.records;

  // Array for records with attachments and their URLs
  const recordsToUpdate = [];

  // Process each record
  for (let i = 0; i < records.length; i++) {
    const record = records[i];
    const attachments = record.getCellValue(selectedField);

    // Only process records with attachments
    if (attachments && attachments.length > 0) {
      // Extract URLs from attachments
      const attachmentUrls = attachments.map(attachment => attachment.url);
      const urlString = attachmentUrls.join(', ');

      // Add to update array
      recordsToUpdate.push({
        id: record.id,
        fields: {
          [fieldToEdit.name]: urlString
        }
      });
    }
  }

  // Update records in batches of 10 — updateRecordsAsync accepts at most 10 per call
  while (recordsToUpdate.length > 0) {
    const batch = recordsToUpdate.slice(0, 10);
    await selectedTable.updateRecordsAsync(batch);
    recordsToUpdate.splice(0, 10);

    // Show progress
    output.text(`Updated ${batch.length} records...`);
  }
}

// Run the script
await convertAttachmentsToUrls();

// Output message to indicate when the script is done
output.text('Records have been updated with attachment URLs', 'success');

How it Works

  1. Select Source Field : Choose an attachment field containing the files you want to convert
  2. Choose Target Field : Select a text field where the comma-separated URLs will be written
  3. Process Records : The script processes each record, extracting URLs from attachments
  4. Output Format : URLs are joined with commas: url1,url2,url3

Requirements

  • An Attachment field with uploaded files
  • A Text field to store the comma-separated URL output

Example

Before:

  • Attachment Field: [file1.pdf, image2.jpg, document3.docx]
  • URL Field: (empty)

After:

  • Attachment Field: [file1.pdf, image2.jpg, document3.docx] (unchanged)
  • URL Field: https://example.com/file1.pdf,https://example.com/image2.jpg,https://example.com/document3.docx

  • API Reference Manual Examples : Browse categorized examples from the NocoDB API reference documentation to quickly access common scripting tasks and operations.
  • Find and Replace : Search and replace text patterns across records in any text-based field with preview and confirmation
  • Randomize Values : Generate random data for empty fields across multiple data types with customizable ranges and constraints
  • Validate Emails : Identify and list all invalid email addresses in email fields for data quality assurance
  • Get Select Options : Extract and display all available options from Single Select or Multiple Select fields in various formats
  • Save View Ordering to Field : Preserve manual record ordering from any view by saving it as sequential numbers in a numeric field
  • Link Records by Field : Link records between two tables using matching field values, with pagination and summary reporting.
  • Unique Field Values Summary : View unique values and their frequencies in any field, with summary and table output
เนื้อหาเอกสารอ้างอิงและภาพประกอบมาจาก NocoDB Official Docs · บทความแนะนำภาษาไทยเรียบเรียงโดย Room64 · เว็บไซต์นี้เป็นคู่มือประกอบการใช้งานโดย Room64 · เอกสารทางการ ↗

มีงานที่อยากให้ Software, AI หรือ Automation ช่วยอยู่ไหม?

เล่า workflow หรือปัญหาที่ทีมกำลังเจอ เราช่วยดูได้ว่าควรใช้ระบบสำเร็จรูป เชื่อมเครื่องมือเดิม หรือพัฒนาเพิ่มเฉพาะส่วนไหน

คุยกับเราทาง LINEhello@room64.net