Examples
App elements
Assets and media
Fundamentals
Intents
Design interaction
Drag and drop
Design elements
Localization
Content replacement
Asset upload
Upload and manage assets directly into Canva.
Running this example
To run this example locally:
-
If you haven't already, create a new app in the Developer Portal(opens in a new tab or window). For more information, refer to our Quickstart guide.
-
In your app's configuration on the Developer Portal(opens in a new tab or window), ensure the "Development URL" is set to
http://localhost:8080
. -
Clone the starter kit:
git clone https://github.com/canva-sdks/canva-apps-sdk-starter-kit.gitcd canva-apps-sdk-starter-kitSHELL -
Install dependencies:
npm installSHELL -
Run the example:
npm run start asset_uploadSHELL -
Click the Preview URL link shown in the terminal to open the example in the Canva editor.
Example app source code
// For usage information, see the README.md file./* eslint-disable no-console */import { Alert, Button, Rows, Text } from "@canva/app-ui-kit";import { upload } from "@canva/asset";import { addAudioTrack } from "@canva/design";import * as styles from "styles/components.css";import { useAddElement } from "utils/use_add_element";import { useFeatureSupport } from "utils/use_feature_support";export const App = () => {const isSupported = useFeatureSupport();const addElement = useAddElement();const importAndAddImage = async () => {// Start uploading the image using Canva's upload API// This creates an asset reference that can be used immediately while the upload continues in the backgroundconst image = await upload({type: "image",mimeType: "image/jpeg",url: "https://www.canva.dev/example-assets/image-import/image.jpg",thumbnailUrl:"https://www.canva.dev/example-assets/image-import/thumbnail.jpg",width: 540,height: 720,aiDisclosure: "none",});// Add the image element to the current design using the asset reference// Canva will display the thumbnail initially and replace it with the full image once upload completesawait addElement({type: "image",ref: image.ref,altText: {text: "a photo of buildings by the water",decorative: undefined,},});// Wait for the upload to complete to handle any upload errors// In production apps, this should include proper error handling and user feedbackawait image.whenUploaded();// Upload completed successfullyconsole.log("Upload complete!");};const importAndAddVideo = async () => {// Start uploading the video using Canva's upload API// Videos support both image and video thumbnails for better preview experienceconst queuedVideo = await upload({type: "video",mimeType: "video/mp4",url: "https://www.canva.dev/example-assets/video-import/video.mp4",thumbnailImageUrl:"https://www.canva.dev/example-assets/video-import/thumbnail-image.jpg",thumbnailVideoUrl:"https://www.canva.dev/example-assets/video-import/thumbnail-video.mp4",width: 405,height: 720,aiDisclosure: "none",});// Add the video element to the current design using the asset reference// The video thumbnail will be shown initially, replaced with the full video once upload completesawait addElement({type: "video",ref: queuedVideo.ref,altText: {text: "a video of building with yellow spinning wheel",decorative: undefined,},});// Wait for the upload to complete to handle any upload errors// In production apps, this should include proper error handling and user feedbackawait queuedVideo.whenUploaded();// Upload completed successfullyconsole.log("Upload complete!");};const importAndAddAudio = async () => {// Start uploading the audio file using Canva's upload API// Audio uploads require duration metadata and optionally a titleconst queuedAudio = await upload({type: "audio",mimeType: "audio/mp3",url: "https://www.canva.dev/example-assets/audio-import/audio.mp3",durationMs: 86047,title: "Example audio",aiDisclosure: "none",});// Add the audio to the design as a new audio track (not supported in all design types)// Audio tracks are added to the timeline and play in the background of the designawait addAudioTrack({ref: queuedAudio.ref,});// Wait for the upload to complete to handle any upload errors// In production apps, this should include proper error handling and user feedbackawait queuedAudio.whenUploaded();// Upload completed successfullyconsole.log("Upload complete!");};return (<div className={styles.scrollContainer}><Rows spacing="3u"><Text>This example demonstrates how apps can import video, audio and imageassets into Canva.</Text><Rows spacing="1.5u"><Button onClick={importAndAddImage} variant="secondary" stretch>Import image</Button><Button onClick={importAndAddVideo} variant="secondary" stretch>Import video</Button><ButtononClick={importAndAddAudio}variant="secondary"// addAudioTrack is not supported in certain design types such as docsdisabled={!isSupported(addAudioTrack)}stretch>Import audio</Button></Rows>{!isSupported(addAudioTrack) && <UnsupportedAlert />}</Rows></div>);};const UnsupportedAlert = () => (<Alert tone="warn">Sorry, the required feature (addAudioTrack) is not supported in the currentdesign.</Alert>);
TYPESCRIPT
// For usage information, see the README.md file.import { AppUiProvider } from "@canva/app-ui-kit";import { createRoot } from "react-dom/client";import "@canva/app-ui-kit/styles.css";import { App } from "./app";const root = createRoot(document.getElementById("root") as Element);function render() {root.render(<AppUiProvider><App /></AppUiProvider>,);}render();// Hot Module Replacement for development (automatically reloads the app when changes are made)if (module.hot) {module.hot.accept("./app", render);}
TYPESCRIPT
# Asset uploadDemonstrates how to upload and import various media types (images, videos, audio) into Canva designs using the upload function. Shows asynchronous upload handling, thumbnail support, and design type compatibility checks.For API reference docs and instructions on running this example, see: https://www.canva.dev/docs/apps/examples/asset-upload/.Related examples: See digital_asset_management for external asset browsing, or drag_and_drop examples for alternative asset insertion patterns.NOTE: This example differs from what is expected for public apps to pass a Canva review:- Static assets are used for demonstration purposes only. Production apps should host assets on a CDN/hosting service and use the `upload` function from the `@canva/asset` package- Console.log statements are used for debugging purposes but should be replaced with proper error handling and logging in production apps- ESLint rule `no-console` is disabled for example purposes only. Production apps should not disable linting rules without proper justification- Error handling is simplified for demonstration. Production apps must implement comprehensive error handling with clear user feedback and graceful failure modes- Internationalization is not implemented. Production apps must support multiple languages using the `@canva/app-i18n-kit` package to pass Canva review requirements
MARKDOWN
API reference
Need help?
- Join our Community Forum(opens in a new tab or window)
- Report issues with this example on GitHub(opens in a new tab or window)