# Convert Attachments to URLs

> Part of the NocoDB documentation (Workflows > Scripts > Examples). Index of all pages: https://nocodb.com/llms.txt. Any docs page is available as Markdown by adding `.md` to its URL.

URL: https://nocodb.com/docs/workflows/scripts/examples/convert-attachments-to-urls
Last updated: 2026-09-25

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.

```javascript
/**
 * 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`

---

## Related pages

- [API Reference Manual Examples](https://nocodb.com/docs/workflows/scripts/examples/api-ref-manual-examples.md): Browse categorized examples from the NocoDB API reference documentation to quickly access common scripting tasks and operations.
- [Find and Replace](https://nocodb.com/docs/workflows/scripts/examples/find-and-replace.md): Search and replace text patterns across records in any text-based field with preview and confirmation
- [Randomize Values](https://nocodb.com/docs/workflows/scripts/examples/randomize-values.md): Generate random data for empty fields across multiple data types with customizable ranges and constraints
- [Validate Emails](https://nocodb.com/docs/workflows/scripts/examples/validate-emails.md): Identify and list all invalid email addresses in email fields for data quality assurance
- [Get Select Options](https://nocodb.com/docs/workflows/scripts/examples/select-options.md): Extract and display all available options from Single Select or Multiple Select fields in various formats
- [Save View Ordering to Field](https://nocodb.com/docs/workflows/scripts/examples/save-view-ordering.md): Preserve manual record ordering from any view by saving it as sequential numbers in a numeric field
- [Link Records by Field](https://nocodb.com/docs/workflows/scripts/examples/link-records-by-field.md): Link records between two tables using matching field values, with pagination and summary reporting.
- [Unique Field Values Summary](https://nocodb.com/docs/workflows/scripts/examples/unique-field-values-summary.md): View unique values and their frequencies in any field, with summary and table output
