Skip to content

Product Attachments

Module: Magenx_ProductAttachments · storefront flag features.productAttachments

Attach files to a product: manuals, data sheets, care instructions, certificates. Upload them on the product edit page, or link to a file hosted elsewhere. They can be attached to the sales emails Magento sends, and listed as downloads on the product page. The browser never sees where a file really lives.

Downloadable attachments on a product page
Attachments on the product page.
  1. Enable Stores > Configuration > Magenx > Product Attachments > Enabled.
  2. Open Catalog > Products, edit a product, and find the Product Attachments section.
  3. Upload files, then save the product. Each new file becomes a row, titled after its file name.
  4. In the Attachments grid, change titles and sort order. To link an external file, click Add Attachment, set Type to External Link, and enter a title and an http(s) URL.
  5. To remove an attachment, delete its row and save. An uploaded file is deleted with its row.

Sales emails. Uploaded files of every product in an order are attached to the emails chosen in Attach To (order, invoice, shipment, credit memo).

  • External links are never mailed. A slow external host must not delay an order confirmation.
  • Order comment and update emails never carry attachments. They are sent many times over an order’s life.
  • A missing, oversized or unreadable file is skipped and logged. The email is still sent.

Product page. With Show On Product Page on, the product page lists its attachments as download chips. This setting is separate from Enabled: you can email files without publishing them, or the reverse.

File (media or external host)MagentoStorefront /api/download/idBrowserFile (media or external host)MagentoStorefront /api/download/idBrowserdownload attachment 12where is attachment 12? (server-to-server)location, if the product page is publicfetchbytesstream file

The storefront fetches the file and streams it, so the browser only ever sees /api/download/<id>. An attachment is only served when its product page is itself public on that store.

  • Executable and script file types (php, phtml, phar, sh, exe, js, html, svg, xml and similar) are always refused, whatever Allowed Extensions says.
  • The file type is read from the file’s content, not its name.
  • External links must be absolute http(s) URLs.
  • Anyone who may edit the product may attach files to it.

Attach files

  1. With the feature on, the product edit screen shows an attachments section.
  2. The manager uploads files; each is stored immediately in the product's folder.
  3. On product save, each new file becomes an attachment titled after its file name.
  4. Titles and order are edited in a list; external links can be added with title and address.
  5. Removing an attachment and saving deletes it, and its file for uploads.

SKU renamed

  1. The product's folder moves and every upload follows.

Email

  1. A customer orders products with uploads.
  2. The selected emails carry those files, within count and size budgets.
  3. Missing, too large or unreadable files are skipped and logged; the email still goes. External links are never emailed; order update emails never carry files.

Download from the product page

  1. With product-page display on, the product returns attachment details (id, title, type, extension, file type, size).
  2. The shopper clicks one; the storefront's download route calls the server-only lookup with the id.
  3. If the attachment's product is public in the store view, the lookup returns the location; the route fetches and streams the file.

These always hold:

  • No stored path points outside the attachments area.
  • No executable or active type is ever stored.
  • The product details never contain a usable location.
  • An attachment problem never prevents an order email.
  • The download lookup reveals nothing a visitor of public product pages could not see.
  • Files in an email = uploads of ordered products in their order, until the count or total size is reached.
SituationWhat happens
SKU containing ../.Folder name cleaned, stays inside the area.
Script disguised with a document extension.Refused by content check.
External link javascript:….Refused on save and on lookup.
Upload's file missing on disk.Skipped in email; logged.
15 files of 3 MB on one order.Files within 20 MB / 10 attached; rest skipped; email sent.
Download id of a disabled product.Empty.
Download id of a product not sold on this website.Empty.
Feature off.No section; uploads refused.
  • Any product; storefront display only for public products.
  • Attachments on categories, content pages or orders.
  • Downloads restricted to buyers or customer groups.
  • Emailing external links, or fetching external files in the back office.
  • Versioning or download statistics.
Terminal window
composer require magenxcommerce/module-product-attachments
bin/magento module:enable Magenx_ProductAttachments
bin/magento setup:upgrade
bin/magento setup:di:compile # production mode only
bin/magento cache:flush
  • PHP ~8.4.0||~8.5.0, Magento 2.4.8.

Stores > Configuration > Magenx > Product Attachments

General

SettingDefaultScopeNotes
Enabled
magenx_product_attachments/general/enabled
NoStore viewYes/No. Master switch. Off by default: the Product Attachments fieldset is absent from the product edit page, uploads are refused, and no email carries attachments. Files already in the media folder are left untouched.
Media Directory
magenx_product_attachments/general/media_directory
product_attachmentsGlobalText. Folder under pub/media holding one sub-folder per product, named after the product SKU (or its numeric id). Files dropped there by hand are picked up exactly like uploaded ones. One path segment: letters, digits, dot, dash, underscore.
Attach To
magenx_product_attachments/general/attach_to
orderStore viewMultiple select. Shown when Enabled = Yes. Which sales email carries the files. Order comment/update emails are never attached to, only the emails selected here.
Show On Product Page
magenx_product_attachments/general/show_on_storefront
NoStore viewYes/No. Independent of Enabled above: lists this product's attachments (uploaded files and external links) as downloadable chips on its storefront page, between Product Features and Product Description. Off by default — a merchant can mail attachments without publishing them, or the reverse.

Limits

SettingDefaultScopeNotes
Allowed Extensions
magenx_product_attachments/limits/allowed_extensions
pdf,doc,docx,xls,xlsx,csv,txt,rtf,odt,ods,zip,jpg,jpeg,png,gif,webpGlobalText. Comma-separated, no dots. Applies to uploads AND to files dropped in by hand — anything else in the folder is ignored, never mailed. Executable types (php, phtml, sh, exe, …) are always refused whatever is listed here.
Maximum File Size (bytes)
magenx_product_attachments/limits/max_file_size
10485760GlobalText. Per file, on upload and on attach. Default 10485760 (10 MB). A larger file already in the folder is skipped and logged.
Maximum Total Size Per Email (bytes)
magenx_product_attachments/limits/max_total_size
20971520Store viewText. Shown when magenx_product_attachments/general/enabled = Yes. Default 20971520 (20 MB). Most mail servers reject more; files past the budget are skipped and logged rather than the email failing.
Maximum Files Per Email
magenx_product_attachments/limits/max_count
10Store viewText. Shown when magenx_product_attachments/general/enabled = Yes. Default 10. An order of many products can otherwise mail dozens of files.

Grant these under System > Permissions > User Roles > Role Resources:

ResourceUnderID
Product Attachments SettingsStores > Settings > ConfigurationMagenx_ProductAttachments::config

ProductInterface.attachments lists titles, types, sizes and MIME types, never a location. productAttachmentDownload returns the location and is meant only for the storefront server. It is kept off the browser allowlist.

Queries

productAttachmentDownload(id: Int!): ProductAttachmentDownload

SERVER-ONLY: resolves an attachment id to its actual, fetchable location. Intended to be called only server-to-server by the storefront's /api/download/[id] route, never from a browser. Do NOT add to a persisted-query allowlist.

ArgumentTypeDescription
idInt!The attachment id from ProductAttachment.id.

Fields added to Magento types

FieldTypeDescription
ProductInterface.attachments[ProductAttachment]This product's downloadable attachments (uploaded files and external links), ordered for display. Null when the feature or its storefront toggle is off, or the product has none.

Types

type ProductAttachment - One product attachment's metadata — never its real file path or external URL. Download it via productAttachmentDownload(id: ...).
FieldTypeDescription
idInt!Opaque attachment id. Pass it to /api/download/[id] on the storefront (or, server-to-server, to productAttachmentDownload) to fetch the file.
titleString!Display label.
typeString!upload or external.
file_extensionStringLowercased file extension without the dot, when known — e.g. pdf.
mime_typeStringMIME type, when known.
sizeIntSize in bytes, when known. Null for an external link until it has been downloaded once.
type ProductAttachmentDownload - Result of productAttachmentDownload — the real, otherwise-hidden location of one attachment.
FieldTypeDescription
typeString!upload or external.
file_urlString!The actual URL to fetch the bytes from — a pub/media URL for an upload, the merchant-entered URL for an external link. Never expose this to a browser.
filenameString!Suggested filename, with extension, for the Content-Disposition header.
mime_typeStringMIME type, when known. Falls back to application/octet-stream if null.
TermMeaning
AttachmentProduct, type, title, order, and either a stored file or an external link.
UploadA file stored in the attachments area, in a folder per product SKU.
External linkAn absolute http(s) address of a file hosted elsewhere.
Attach-to emailsThe order emails that carry uploads.
Download lookupServer-only call that turns an attachment id into its real location.
Download routeStorefront server route that fetches the file and streams it to the browser.
Public productEnabled, visible in catalog or search, sold on the request's website.