Makes it possible for an app to check if a media file, such as an image, has finished uploading.
Usage
import { getContent } from "@canva/content";(async () => {// Initialize the APIconst content = getContent();// Start uploading the mediaconst upload = await content.queueMediaUpload({// options go here});// Do something when the upload is doneconst result = await upload.whenUploaded();if (result.type === "done") {console.log("The media has finished uploading!");} else {throw new Error(`Unexpected response type: ${result.reason.type}`);}})();
Returns
Returns a Promise
. The contents of this Promise
depends on whether or not the media has successfully uploaded.
If the media is successfully uploaded, the following result is returned:
An object that represents a successful result.
object
This is always set to "done"
.
string
If the media is not successfully uploaded, the following result is returned:
An object that represents a successful result.
object
This is always set to "failed"
.
string
The reason for the error.
object
An error code that identifies what went wrong.
string
Error codes
The following error codes may appear in the reason.type
property:
oversized_media
The size of the media file exceeds the maximum allowed file siz:
- For images, this is 25MB
- For videos, this is 100MB
oversized_media_dimensions
The number of pixels in the media file exceeds the maximum allowed pixels (250 megapixels).
mismatched_mime_type
There's a mismatch between the value of the mimeType
property and the actual MIME type of the file.
unavailable_media
Canva was not able to download the media file specified in the url
property.
timeout
The upload process timed out before the upload was able to complete. The timeout duration for an image file is 5 seconds.
unknown_error
Something went wrong, but Canva wasn't able to determine the reason for the error.