Asset upload

Upload and manage assets directly into Canva.

Running this example

To run this example locally:

  1. 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.

  2. 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.

  3. Clone the starter kit:

    git clone https://github.com/canva-sdks/canva-apps-sdk-starter-kit.git
    cd canva-apps-sdk-starter-kit
    SHELL
  4. Install dependencies:

    npm install
    SHELL
  5. Run the example:

    npm run start asset_upload
    SHELL
  6. 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
const 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 to the design, using the thumbnail at first, and replacing
// with the full image once the upload completes
await addElement({
type: "image",
ref: image.ref,
altText: {
text: "a photo of buildings by the water",
decorative: undefined,
},
});
// Wait for the upload to finish so we can report errors if it fails to
// upload
await image.whenUploaded();
// upload is completed
console.log("Upload complete!");
};
const importAndAddVideo = async () => {
// Start uploading the video
const 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 to the design, using the thumbnail at first, and replacing
// with the full image once the upload completes
await addElement({
type: "video",
ref: queuedVideo.ref,
altText: {
text: "a video of building with yellow spinning wheel",
decorative: undefined,
},
});
// Wait for the upload to finish so we can report errors if it fails to
// upload
await queuedVideo.whenUploaded();
// upload is completed
console.log("Upload complete!");
};
const importAndAddAudio = async () => {
const 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
await addAudioTrack({
ref: queuedAudio.ref,
});
// Wait for the upload to finish so we can report errors if it fails to
// upload
await queuedAudio.whenUploaded();
// upload is completed
console.log("Upload complete!");
};
return (
<div className={styles.scrollContainer}>
<Rows spacing="3u">
<Text>
This example demonstrates how apps can import video, audio and image
assets 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>
<Button
onClick={importAndAddAudio}
variant="secondary"
// addAudioTrack is not supported in certain design types such as docs.
disabled={!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 current
design.
</Alert>
);
TYPESCRIPT
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();
if (module.hot) {
module.hot.accept("./app", render);
}
TYPESCRIPT
# Asset upload
Demonstrates 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?