> ## Documentation Index
> Fetch the complete documentation index at: https://spreecommerce.org/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Place a library file on a product

> Puts a file that is already in the library onto this product. The new
record shares the source's file rather than copying it, so nothing is
uploaded and no image is reprocessed; it carries its own alt text,
position and variant links from here on.


**Required scope:** `write_products` (for API-key authentication).



## OpenAPI

````yaml /api-reference/admin.yaml post /api/v3/admin/products/{product_id}/media
openapi: 3.0.3
info:
  title: Admin API
  contact:
    name: Spree Commerce
    url: https://spreecommerce.org
    email: hello@spreecommerce.org
  description: >
    Spree Admin API v3 - Administrative API for managing products, orders, and
    store settings.


    ## Authentication


    The Admin API requires a secret API key passed in the `x-spree-api-key`
    header.

    Secret API keys can be generated in the Spree admin dashboard.


    ## Response Format


    All responses are JSON. List endpoints return paginated responses with
    `data` and `meta` keys.

    Single resource endpoints return a flat JSON object.


    ## Resource IDs


    Every resource is identified by an opaque string ID (e.g. `prod_86Rf07xd4z`,

    `variant_k5nR8xLq`, `or_UkLWZg9DAJ`). Use these IDs everywhere — URL paths,

    request bodies, and Ransack filters all accept them directly.


    ## Error Handling


    Errors return a consistent format:

    ```json

    {
      "error": {
        "code": "validation_error",
        "message": "Validation failed",
        "details": { "name": ["can't be blank"] }
      }
    }

    ```
  version: v3
servers:
  - url: http://{defaultHost}
    variables:
      defaultHost:
        default: localhost:3000
security: []
tags:
  - name: Authentication
    description: Admin user login, logout, token refresh, and current user profile
  - name: Allowed Origins
    description: CORS allowlist for storefront and admin client origins
  - name: API Keys
    description: Secret and publishable API keys
  - name: Categories
    description: >-
      Hierarchical product categories — tree management, repositioning, and
      product assignments
  - name: Channels
    description: >-
      Sales channels, product publication across channels, and per-channel order
      routing rules
  - name: Custom Fields
    description: >-
      Custom field definitions for products, variants, customers, and other
      resources
  - name: Customer Groups
    description: >-
      Customer groups for segmenting customers (e.g. wholesale, VIP) used by
      pricing and promotions
  - name: Customers
    description: Customer profiles, addresses, credit cards, and store credits
  - name: Email Templates
    description: >-
      Customer email templates, the email layout and shared partials: drafts,
      previews, publishing and history
  - name: Exports
    description: Async CSV exports of admin resources
  - name: Files
    description: Uploading the files that product media, imports, logos and documents use
  - name: Fulfillments
    description: Order fulfillments — shipments, fulfill, cancel, resume, split
  - name: Gift Cards
    description: Gift cards and gift card batches
  - name: Imports
    description: >-
      Async CSV imports of admin resources, with per-row status and failed-row
      retry
  - name: Markets
    description: >-
      Markets — geographic groupings of countries used for pricing, tax, and
      fulfillment rules
  - name: Option Types
    description: >-
      Option types and option values used to build product variants (e.g. Size,
      Color)
  - name: Orders
    description: Orders, order items, applied gift cards, and applied store credits
  - name: Payment Methods
    description: Configured payment providers and their available types
  - name: Payments
    description: Order payments — list, capture, void
  - name: Pricing
    description: >-
      Prices and price lists for currency-, market-, and customer-group-specific
      pricing
  - name: Products
    description: >-
      Products, taxons/categories, product custom field values, and bulk product
      operations
  - name: Policies
    description: The store's legal documents — terms of service, privacy, returns, shipping
  - name: Reasons
    description: >-
      Merchant-owned vocabularies for why a return, claim, refund, cancellation
      or tax exemption happened
  - name: Promotions
    description: Promotions, promotion rules, promotion actions, and coupon codes
  - name: Refunds
    description: Order refunds
  - name: Settings
    description: Store-level settings — store profile, tags, and configuration
  - name: Staff
    description: Admin users, roles, and invitations to the store
  - name: Stock Locations
    description: Warehouses and physical fulfillment locations
  - name: Store Credits
    description: Prepaid customer balances across all customers, and each balance's ledger
  - name: Variants
    description: >-
      Product variants — the individual SKUs (size/color combinations) sold
      under a product
  - name: Webhooks
    description: Webhook endpoints and webhook delivery history
paths:
  /api/v3/admin/products/{product_id}/media:
    parameters:
      - name: product_id
        in: path
        required: true
        description: Product ID
        schema:
          type: string
    post:
      tags:
        - Media
      summary: Place a library file on a product
      description: |-
        Puts a file that is already in the library onto this product. The new
        record shares the source's file rather than copying it, so nothing is
        uploaded and no image is reprocessed; it carries its own alt text,
        position and variant links from here on.


        **Required scope:** `write_products` (for API-key authentication).
      parameters:
        - name: x-spree-api-key
          in: header
          required: true
          schema:
            type: string
        - name: Authorization
          in: header
          required: true
          description: Bearer token for admin authentication
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/MediaCreateParams'
        required: true
      responses:
        '201':
          description: file placed
          content:
            application/json:
              example:
                id: media_gbHJdmfrXB
                product_id: prod_gbHJdmfrXB
                variant_ids: []
                position: 1
                alt: Front view
                media_type: image
                external_video_url: null
                focal_point_x: null
                focal_point_y: null
                video_provider: null
                video_embed_url: null
                video_url: null
                poster_url: null
                original_url: >-
                  http://localhost:3000/rails/active_storage/blobs/proxy/eyJfcmFpbHMiOnsiZGF0YSI6MSwicHVyIjoiYmxvYl9pZCJ9fQ==--f34e09859ba330793d603f7c22466732a512f47b/thinking-cat.jpg
                mini_url: >-
                  http://localhost:3000/rails/active_storage/representations/proxy/eyJfcmFpbHMiOnsiZGF0YSI6MSwicHVyIjoiYmxvYl9pZCJ9fQ==--f34e09859ba330793d603f7c22466732a512f47b/eyJfcmFpbHMiOnsiZGF0YSI6eyJmb3JtYXQiOiJ3ZWJwIiwicmVzaXplX3RvX2ZpbGwiOlsxMjgsMTI4XSwic2F2ZXIiOnsic3RyaXAiOnRydWUsInF1YWxpdHkiOjc1LCJsb3NzbGVzcyI6ZmFsc2UsImFscGhhX3EiOjg1LCJyZWR1Y3Rpb25fZWZmb3J0Ijo2LCJzbWFydF9zdWJzYW1wbGUiOnRydWV9fSwicHVyIjoidmFyaWF0aW9uIn19--4360105231729cff27f4227ea4304fac7e08a65e/thinking-cat.jpg
                small_url: >-
                  http://localhost:3000/rails/active_storage/representations/proxy/eyJfcmFpbHMiOnsiZGF0YSI6MSwicHVyIjoiYmxvYl9pZCJ9fQ==--f34e09859ba330793d603f7c22466732a512f47b/eyJfcmFpbHMiOnsiZGF0YSI6eyJmb3JtYXQiOiJ3ZWJwIiwicmVzaXplX3RvX2ZpbGwiOlsyNTYsMjU2XSwic2F2ZXIiOnsic3RyaXAiOnRydWUsInF1YWxpdHkiOjc1LCJsb3NzbGVzcyI6ZmFsc2UsImFscGhhX3EiOjg1LCJyZWR1Y3Rpb25fZWZmb3J0Ijo2LCJzbWFydF9zdWJzYW1wbGUiOnRydWV9fSwicHVyIjoidmFyaWF0aW9uIn19--bba92085e6437e846cd0b9fca8d58f9c0b723eba/thinking-cat.jpg
                medium_url: >-
                  http://localhost:3000/rails/active_storage/representations/proxy/eyJfcmFpbHMiOnsiZGF0YSI6MSwicHVyIjoiYmxvYl9pZCJ9fQ==--f34e09859ba330793d603f7c22466732a512f47b/eyJfcmFpbHMiOnsiZGF0YSI6eyJmb3JtYXQiOiJ3ZWJwIiwicmVzaXplX3RvX2ZpbGwiOls0MDAsNDAwXSwic2F2ZXIiOnsic3RyaXAiOnRydWUsInF1YWxpdHkiOjc1LCJsb3NzbGVzcyI6ZmFsc2UsImFscGhhX3EiOjg1LCJyZWR1Y3Rpb25fZWZmb3J0Ijo2LCJzbWFydF9zdWJzYW1wbGUiOnRydWV9fSwicHVyIjoidmFyaWF0aW9uIn19--242625616b48cff11334ec85f04b68042261f208/thinking-cat.jpg
                large_url: >-
                  http://localhost:3000/rails/active_storage/representations/proxy/eyJfcmFpbHMiOnsiZGF0YSI6MSwicHVyIjoiYmxvYl9pZCJ9fQ==--f34e09859ba330793d603f7c22466732a512f47b/eyJfcmFpbHMiOnsiZGF0YSI6eyJmb3JtYXQiOiJ3ZWJwIiwicmVzaXplX3RvX2ZpbGwiOls3MjAsNzIwXSwic2F2ZXIiOnsic3RyaXAiOnRydWUsInF1YWxpdHkiOjc1LCJsb3NzbGVzcyI6ZmFsc2UsImFscGhhX3EiOjg1LCJyZWR1Y3Rpb25fZWZmb3J0Ijo2LCJzbWFydF9zdWJzYW1wbGUiOnRydWV9fSwicHVyIjoidmFyaWF0aW9uIn19--0fa218972b6a0c500c744b36fcd9fee8a0b3e995/thinking-cat.jpg
                xlarge_url: >-
                  http://localhost:3000/rails/active_storage/representations/proxy/eyJfcmFpbHMiOnsiZGF0YSI6MSwicHVyIjoiYmxvYl9pZCJ9fQ==--f34e09859ba330793d603f7c22466732a512f47b/eyJfcmFpbHMiOnsiZGF0YSI6eyJmb3JtYXQiOiJ3ZWJwIiwicmVzaXplX3RvX2ZpbGwiOlsyMDAwLDIwMDBdLCJzYXZlciI6eyJzdHJpcCI6dHJ1ZSwicXVhbGl0eSI6NzUsImxvc3NsZXNzIjpmYWxzZSwiYWxwaGFfcSI6ODUsInJlZHVjdGlvbl9lZmZvcnQiOjYsInNtYXJ0X3N1YnNhbXBsZSI6dHJ1ZX19LCJwdXIiOiJ2YXJpYXRpb24ifX0=--4d30e1109a0549e5024fddaecdff7a8eb271730d/thinking-cat.jpg
                og_image_url: >-
                  http://localhost:3000/rails/active_storage/representations/proxy/eyJfcmFpbHMiOnsiZGF0YSI6MSwicHVyIjoiYmxvYl9pZCJ9fQ==--f34e09859ba330793d603f7c22466732a512f47b/eyJfcmFpbHMiOnsiZGF0YSI6eyJmb3JtYXQiOiJ3ZWJwIiwicmVzaXplX3RvX2ZpbGwiOlsxMjAwLDYzMF0sInNhdmVyIjp7InN0cmlwIjp0cnVlLCJxdWFsaXR5Ijo3NSwibG9zc2xlc3MiOmZhbHNlLCJhbHBoYV9xIjo4NSwicmVkdWN0aW9uX2VmZm9ydCI6Niwic21hcnRfc3Vic2FtcGxlIjp0cnVlfX0sInB1ciI6InZhcmlhdGlvbiJ9fQ==--24a2fdb966aceb15786df6c2f570db0d2624d262/thinking-cat.jpg
                external_references: {}
                created_at: '2026-01-15T12:00:00.000Z'
                updated_at: '2026-01-15T12:00:00.000Z'
                attached: true
                filename: thinking-cat.jpg
                content_type: image/jpeg
                byte_size: 18090
                embed_url: >-
                  http://localhost:3000/rails/active_storage/representations/proxy/eyJfcmFpbHMiOnsiZGF0YSI6MSwicHVyIjoiYmxvYl9pZCJ9fQ==--f34e09859ba330793d603f7c22466732a512f47b/eyJfcmFpbHMiOnsiZGF0YSI6eyJmb3JtYXQiOiJ3ZWJwIiwicmVzaXplX3RvX2xpbWl0IjpbMTIwMCwxMjAwXSwic2F2ZXIiOnsic3RyaXAiOnRydWUsInF1YWxpdHkiOjc1LCJsb3NzbGVzcyI6ZmFsc2UsImFscGhhX3EiOjg1LCJyZWR1Y3Rpb25fZWZmb3J0Ijo2LCJzbWFydF9zdWJzYW1wbGUiOnRydWV9fSwicHVyIjoidmFyaWF0aW9uIn19--67e4c38f8d0453b5c5c0d3d44862a9d1bd79c07c/thinking-cat.jpg
                signed_id: >-
                  eyJfcmFpbHMiOnsiZGF0YSI6MSwiZXhwIjoiMjAyNi0wMS0xNlQxMjowMDowMC4wMDBaIiwicHVyIjoiYmxvYl9pZCJ9fQ==--a9cd29e72a70654182038480207bd929343f6a07
                viewable_id: prod_gbHJdmfrXB
                download_url: >-
                  http://localhost:3000/rails/active_storage/blobs/redirect/eyJfcmFpbHMiOnsiZGF0YSI6MSwicHVyIjoiYmxvYl9pZCJ9fQ==--f34e09859ba330793d603f7c22466732a512f47b/thinking-cat.jpg?disposition=attachment
                metadata: {}
                viewable_type: product
              schema:
                $ref: '#/components/schemas/Media'
      security:
        - api_key: []
          bearer_auth: []
      x-codeSamples:
        - lang: javascript
          label: Spree Admin SDK
          source: >-
            import { createAdminClient } from '@spree/admin-sdk'


            const client = createAdminClient({
              baseUrl: 'https://your-store.com',
              secretKey: 'sk_xxx',
            })


            // Places a library file on the product. The file is shared, not
            copied.

            const media = await client.products.media.create('prod_UkLWZg9DAJ',
            {
              source_media_id: 'media_UkLWZg9DAJ',
              alt: 'Front view',
            })
        - lang: bash
          label: Spree CLI
          source: >-
            spree api post /products/{product_id}/media -d
            '{"source_media_id":"media_UkLWZg9DAJ","alt":"Front view"}'
components:
  schemas:
    MediaCreateParams:
      type: object
      properties:
        external_references:
          type: object
          additionalProperties: true
          description: >-
            Identities the record has in external systems, keyed by system: the
            same `{ system: external_id }` map the Admin API renders, so what
            you read can be sent straight back. Systems you do not name keep the
            reference they have. A list of `{ system, external_id }` entries is
            accepted too.
        alt:
          type: string
          example: Front view
          nullable: true
        position:
          type: integer
          example: 1
        media_type:
          type: string
          enum:
            - image
            - video
            - external_video
          description: >-
            Defaults to `image`. `video` needs a `signed_id`; `external_video`
            needs an `external_video_url`.
          example: image
        external_video_url:
          type: string
          description: >-
            YouTube or Vimeo link. Required when `media_type` is
            `external_video`.
          nullable: true
        poster_signed_id:
          type: string
          description: A `signed_id` from `files.upload()` for a video's poster frame.
        focal_point_x:
          type: number
          description: Where the image is anchored when cropped, from 0 to 1.
          nullable: true
        focal_point_y:
          type: number
          description: Where the image is anchored when cropped, from 0 to 1.
          nullable: true
        attachment:
          type: string
          description: >-
            The file itself, sent as multipart form data. JSON clients upload
            first and send `signed_id`.
        url:
          type: string
          description: >-
            Fetch an image from this URL, in the background. Images only: an
            external video uses `external_video_url`.
        signed_id:
          type: string
          description: A `signed_id` from `files.upload()` for the media file itself.
        source_media_id:
          type: string
          description: >-
            Place a file that is already in the library. The new row shares the
            source file rather than copying it, and takes its own alt, position
            and variant links from here.
        variant_ids:
          type: array
          items:
            type: string
          description: >-
            Variants to link this product-level media to. Variants of other
            products are dropped.
    Media:
      type: object
      properties:
        id:
          type: string
        product_id:
          type: string
          nullable: true
        variant_ids:
          type: array
          items:
            type: string
        position:
          type: number
        alt:
          type: string
          nullable: true
        media_type:
          type: string
          enum:
            - image
            - video
            - external_video
        external_video_url:
          type: string
          nullable: true
        focal_point_x:
          type: number
          nullable: true
        focal_point_y:
          type: number
          nullable: true
        video_provider:
          type: string
          nullable: true
        video_embed_url:
          type: string
          nullable: true
        video_url:
          type: string
          nullable: true
        poster_url:
          type: string
          nullable: true
        original_url:
          type: string
          nullable: true
        mini_url:
          type: string
          nullable: true
        small_url:
          type: string
          nullable: true
        medium_url:
          type: string
          nullable: true
        large_url:
          type: string
          nullable: true
        xlarge_url:
          type: string
          nullable: true
        og_image_url:
          type: string
          nullable: true
        external_references:
          type: object
        created_at:
          type: string
        updated_at:
          type: string
        attached:
          type: boolean
        filename:
          type: string
          nullable: true
        content_type:
          type: string
          nullable: true
        byte_size:
          type: number
          nullable: true
        embed_url:
          type: string
          nullable: true
        signed_id:
          type: string
          nullable: true
        viewable_id:
          type: string
          nullable: true
        download_url:
          type: string
          nullable: true
        metadata:
          type: object
        viewable_type:
          type: string
          nullable: true
      required:
        - id
        - product_id
        - variant_ids
        - position
        - alt
        - media_type
        - external_video_url
        - focal_point_x
        - focal_point_y
        - video_provider
        - video_embed_url
        - video_url
        - poster_url
        - original_url
        - mini_url
        - small_url
        - medium_url
        - large_url
        - xlarge_url
        - og_image_url
        - external_references
        - created_at
        - updated_at
        - attached
        - filename
        - content_type
        - byte_size
        - embed_url
        - signed_id
        - viewable_id
        - download_url
        - metadata
        - viewable_type
      x-typelizer: true
  securitySchemes:
    api_key:
      type: apiKey
      name: x-spree-api-key
      in: header
      description: Secret API key for admin access
    bearer_auth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: JWT token for admin user authentication

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.