Manage media for products
You can use the GraphQL Admin API to manage the various types of media associated with products. You can also use the Storefront API to retrieve a product's media and display it on a custom storefront. This guide explains the different types of product media, and how to use Shopify APIs to work with them.
App requirements
Anchor link to section titled "App requirements"- Your app can make authenticated requests to the GraphQL Admin API and Storefront API.
- Your app has the
read_products
andwrite_products
access scopes. Learn how to configure your access scopes using Shopify CLI. - You're performing actions on product media that are supported by the API you're working with:
- GraphQL Admin API: Supports uploading media, adding media to a product, retrieving media, and deleting media
- Storefront API: Only supports retrieving media
- You're working within the constraints of the plan-based limits for product media.
- There's a limit to the number of Shopify-hosted videos and 3D models that a store can have. The limit depends on the Shopify plan that the store is on:
- Basic Shopify: 250
- Shopify: 1,000
- Advanced Shopify: 5,000
- Shopify Plus: Contact Plus Support
- There's also a limit to the total storage available per shop. The limit depends on the Shopify plan that the store is on:
- Basic Shopify: 100GB
- Shopify: 300GB
- Advanced Shopify: 300GB
- Shopify Plus: 300GB, contact Plus Support if you need more storage.
- There's a limit to the number of Shopify-hosted videos and 3D models that a store can have. The limit depends on the Shopify plan that the store is on:
Step 1: Upload media to Shopify
Anchor link to section titled "Step 1: Upload media to Shopify"A product can have different media types:
MediaImage
: An image in one of the following formats: PNG, GIF, or JPG. The maximum image size is 4472 x 4472 px, or 20 megapixels. For square images, 2048 x 2048 px looks best.Video
: An MP4 video that's hosted by Shopify. The video runtime must be 10 minutes or shorter. The maximum file size is 1 GB.ExternalVideo
: A video that's hosted on YouTube or Vimeo, specified by its embed URL.Model3d
: A 3D model provided in GLB or USDZ format. The asset can be retrieved in GLB and USDZ formats. The file size must be 500 MB or smaller.
Before you add a piece of media to a product, you can upload it and host it on Shopify. There are two parts to uploading an asset to Shopify:
Generate the upload URL and parameters
Anchor link to section titled "Generate the upload URL and parameters"You can use the stagedUploadsCreate
mutation to generate the values that you need to authenticate multiple uploads. The mutation returns the stagedTargets
array. Each staged target has the following properties:
params
: The parameters that you use to authenticate an upload requesturl
: The URL where you can upload the media assetresourceUrl
: The URL that you pass to productCreateMedia in theoriginalSource
field after the asset has been uploaded
The mutation accepts an input of type stagedUploadInput
, which has the following fields:
Field | Type | Description |
---|---|---|
resource | StagedUploadTargetGenerateUploadResource | Specifies the resource type to upload. Valid media values: VIDEO , MODEL_3D , IMAGE . |
filename | String | The name of the file to upload. |
mimeType | String |
The Media type of the file to upload. Use one of the following values:
|
httpMethod | StagedUploadHttpMethodType | The HTTP method to be used by the staged upload. Valid values: POST (all media types), PUT (images only). |
fileSize | UnsignedInt64 | The size in bytes of the file to upload. |
The following example uses the stagedUploadsCreate
mutation to generate the upload values required to upload an MP4 video and a 3D model.
Upload the asset
Anchor link to section titled "Upload the asset"After generating the parameters and URL for an upload, you need to upload the asset by using a POST or PUT request. The request is formatted differently depending on the media type and the HTTP method that you're using.
3D models: POST request
Anchor link to section titled "3D models: POST request"Use a multipart form, and include all parameters as form inputs in the request body:
Videos: POST request
Anchor link to section titled "Videos: POST request"Use a multipart form, and include all parameters as form inputs in the request body:
Images: POST request
Anchor link to section titled "Images: POST request"Use a multipart form, and include all parameters as form inputs in the request body:
Images: PUT request
Anchor link to section titled "Images: PUT request"Include the parameters as request headers. Additional parameters are already included in the URL:
Step 2: Add media to a product
Anchor link to section titled "Step 2: Add media to a product"You can add new media to a product by using the productCreateMedia
mutation. The mutation takes two arguments:
productId
: The ID of the product that you're adding media to.media
: An array ofCreateMediaInput
objects.
For each CreateMediaInput
object, include the following fields:
Field | Type | Description |
---|---|---|
originalSource | String | The original source of the media object. Can be an external URL for images, YouTube videos, and Vimeo videos, or an upload URL for images, videos, and 3D models hosted by Shopify. For assets hosted by Shopify, use the resourceUrl value returned by the stagedUploadsCreate mutation. |
alt | String | The alt text associated to the media. |
mediaContentType | MediaContentType | The content type of the asset that you're adding. Valid values: IMAGE , VIDEO , EXTERNAL_VIDEO , MODEL_3D . |
The following example adds a Shopify-hosted video to a product:
Step 3: Retrieve media objects
Anchor link to section titled "Step 3: Retrieve media objects"You can retrieve a product's media of all types by using the media
connection on the Product type. The connection returns nodes that implement the Media interface.
The media
connection includes the mediaContentType
field, which you can use to check the media type of each node. Because each media type can return different fields, you can specify the return fields for each type by using fragments:
Retrieve product media by using the Storefront API
Anchor link to section titled "Retrieve product media by using the Storefront API"With the Storefront API, use the media
field on the Product type to query for a product's media. Use a fragment to specify the fields that you want to return for each possible media type.
Step 4: Check whether media is ready to display
Anchor link to section titled "Step 4: Check whether media is ready to display"When you add a piece of media to a product, Shopify needs to process the media before it can be displayed.
The Media
interface includes the status
field, which you can use to check whether the media has been processed. The status
field can return different values.
Step 5: Update product media
Anchor link to section titled "Step 5: Update product media"You can use the productUpdateMedia
mutation to update a piece of media associated with a product. As part of the mutation input, include the following arguments:
productId
: The ID of the product that the media belongs to.media
: An array of media changes to apply.
You can change a media item's alt text or preview image URL. Include the media's ID to identify the media you want to update.
Identify the media to update by its ID. For example, the GraphQL variable below updates the alt text of the MediaImage with ID gid://shopify/MediaImage/42729528
:
The following example shows how to use the productUpdateMedia
mutation to update the alt text of a piece of media. The example uses a JSON variable to provide the media changes, and a fragment to select the return fields based on the media type.
Step 6: Reorder media objects
Anchor link to section titled "Step 6: Reorder media objects"You can reorder a product’s media by using the productReorderMedia
mutation. The mutation accepts two arguments:
id
: The ID of the product whose media you’re reordering.moves
: An array of tuples consisting of a media object’s ID and its new position in the list. For example, the following array would move the media objects to the front of the product’s media list:
The following example adjusts the order of a products first three media assets:
You can use the returned ID for the job to poll for when the reordering job is complete.
Step 7: Delete media objects (optional)
Anchor link to section titled "Step 7: Delete media objects (optional)"To delete media assets from a product, use the productDeleteMedia
mutation. The mutation accepts two arguments:
productId
: The ID of the product whose media you’re deleting.mediaIds
: An array of IDs for the media that you’re deleting.
The following example deletes two media assets from a product:
Media file requirements
Anchor link to section titled "Media file requirements"The following sections provide file format and size requirements and specify any file limitations.
Image file requirements
Anchor link to section titled "Image file requirements"Attribute | Requirement |
---|---|
File size | Maximum of 20 MB (megabytes) |
Resolution | Maximum of 20 MP (megapixels) |
Aspect ratio | Between 100:1 and 1:100 |
File formats | JPEG, PNG, WEBP, HEIC, and GIF |
File names | File names may contain letters, numbers, spaces, and symbols, but must not begin with a period . |
Video file requirements
Anchor link to section titled "Video file requirements"Attribute | Requirement |
---|---|
File size | Maximum of 1 GB (gigabyte) |
Resolution | Maximum resolution of UHD |
Video length | Maximum video length of 10 minutes |
File formats | MOV, MP4, and WEBM |
Minimum width and height | 100 pixels |
Maximum width and height | 4096 pixels |
Maximum frame rate | 120 frames per second |
Minimum video length | 0.25 seconds |
File names | File names may contain letters, numbers, spaces, and symbols, but must not begin with a period . |
Recommended video specifications
Anchor link to section titled "Recommended video specifications"Feature | Recommendation |
---|---|
Aspect ratio | The aspect ratio should be one of the following:
|
Bitrates | Shopify's video pipeline will process incoming videos and auto select the best quality by analyzing the input media and selecting an appropriate bitrate from the ranges below.
|
Frame rate |
|
Resolution |
|
Supported codecs |
|
Supported color spaces |
|
Generic file requirements
Anchor link to section titled "Generic file requirements"Generic files can be any file other than HTML, and are intended for downloading by the customer.
Attribute | Requirement |
---|---|
File size | Maximum of 20 MB |
File formats | Any file type except HTML |
File names | File names may contain letters, numbers, spaces, and symbols, but must not begin with a period . |
File format requirements
Anchor link to section titled "File format requirements"If a shop is on a paid plan, then you can upload most file formats other than HTML.
If a shop is on a trial plan, then you can upload only the following file formats:
- JavaScript (JS)
- CSS
- GIF
- JPEG
- PNG
- JSON
- CSV
- WebP
- HEIC
- Manage media objects on product variants with the GraphQL Admin API.
- Use Liquid to add product media to a store's theme.