whenUploaded

API reference for the whenUploaded method.

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 API
const content = getContent();
// Start uploading the media
const upload = await content.queueMediaUpload({
// options go here
});
// Do something when the upload is done
const 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:

result

An object that represents a successful result.

Type
object
result.type

This is always set to "done".

Type
string

If the media is not successfully uploaded, the following result is returned:

result

An object that represents a successful result.

Type
object
result.type

This is always set to "failed".

Type
string
result.reason

The reason for the error.

Type
object
result.reason.type

An error code that identifies what went wrong.

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