# 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-10-03

A NocoDB script that converts attachment fields into comma-separated lists of URLs for external services.

### Overview

The attachments-to-URLs script reads the attachment fields in your table and converts them into comma-separated URL strings. Use it to send attachment URLs to third-party integration services. These services expect URL strings, not 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**: Select the attachment field that contains the files to convert.
2. **Choose Target Field**: Select the text field for the comma-separated URLs.
3. **Process Records**: The script reads each record and gets the URLs from its attachments.
4. **Output Format**: The script joins the URLs 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): An index of the NocoDB Scripts API reference examples, grouped by category, for common scripting tasks.
- [Find and Replace](https://nocodb.com/docs/workflows/scripts/examples/find-and-replace.md): A NocoDB script that finds and replaces text in any text-based field across records, with a preview and a confirmation.
- [Randomize Values](https://nocodb.com/docs/workflows/scripts/examples/randomize-values.md): A NocoDB script that fills empty fields with random data, for many field types, with ranges and constraints that you set.
- [Validate Emails](https://nocodb.com/docs/workflows/scripts/examples/validate-emails.md): A NocoDB script that finds and lists all invalid email addresses in email fields to check data quality.
- [Get Select Options](https://nocodb.com/docs/workflows/scripts/examples/select-options.md): A NocoDB script that lists all options of a Single Select or Multiple Select field in one of three formats.
- [Save View Ordering to Field](https://nocodb.com/docs/workflows/scripts/examples/save-view-ordering.md): A NocoDB script that saves the record order of a view as sequential numbers in a numeric field.
- [Link Records by Field](https://nocodb.com/docs/workflows/scripts/examples/link-records-by-field.md): A NocoDB script that links records in two tables by matching field values, with pagination and a summary report.
- [Unique Field Values Summary](https://nocodb.com/docs/workflows/scripts/examples/unique-field-values-summary.md): A NocoDB script that shows the unique values in a field and how often each occurs, as a summary and a table.
