Search...
addProductMedia( )
Adds media items by ID to a product.
Description
The addProductMedia()
function returns a Promise that resolves when the adding of
the media (images or videos) to a product has started.
Limitation The URL is not validated and no event is triggered to indicate if the media was added successfully.
Syntax
function addProductMedia(productId: string, media: Array<Media>): Promise<void>
addProductMedia Parameters
NAME
TYPE
DESCRIPTION
productId
string
Product ID.
media
Array<Media>
Sources of media items already uploaded to the Wix site.
Returns
Fulfilled - When the media are added to the product. Rejected - Error message.
Return Type:
Promise<void>
Related Content:
Was this helpful?
Add media items to a product
Copy Code
1/*******************************2 * Backend code - products.jsw *3 *******************************/45import wixStoresBackend from 'wix-stores-backend';67export function addProductMedia(productId, mediaData) {8 return wixStoresBackend.addProductMedia(productId, mediaData);9}1011/*************12 * Page code *13 *************/14import { addProductMedia } from 'backend/myModule';151617// ...1819const productId = ...; // get product ID20const src = "wix:image://v1/1a11a1_..._1a~mv2.jpg/1a11a1_..._1a~mv2.jpg";21const choice = "Color";22const option = "Blue";2324if (choice !== "" && option !== "") {25 const mediaData = [{ // add media item to a choice26 src,27 "choice": {28 choice,29 option30 }31 }]3233} else {34 const mediaData = [{ // add media item to the product35 src36 }]37}3839addProductMedia(productId, mediaData)