public upload()

in packages/roosterjs-react-common/lib/utils/ImageManager.ts [44:90]


    public upload(editor: Editor, image: File, forceFallbackAltValue?: boolean): HTMLImageElement {
        if (!image || image.size === 0) {
            return null;
        }

        const placeholder = this.options.createImagePlaceholder(editor, image);
        if (placeholder === null) {
            return null;
        }

        let altText = "";
        if (forceFallbackAltValue) {
            altText = this.options.fallbackAltValue;
        } else {
            altText = image.name || this.options.fallbackAltValue;
        }

        // note: add identification (to handle undo/redo scenarios)
        const placeholdId = (ImageManager.Id++).toString(10);
        placeholder.setAttribute(PlaceholderDataAttribute, placeholdId);

        this.options.uploadImage(image).then(
            (url: string) => {
                // accepted, so replace the placeholder with final image
                this.idToUrlImageCache[placeholdId] = url;

                if (editor.isDisposed() || !editor.contains(placeholder)) {
                    return;
                }

                this.replacePlaceholder(placeholder, url, editor, altText || "Image");
                this.triggerChangeEvent(editor);
            },
            () => {
                // rejected, so remove the placeholder
                if (editor.isDisposed() || !editor.contains(placeholder)) {
                    return;
                }

                this.idToUrlImageCache[placeholdId] = null;
                this.removePlaceholder(placeholder, editor);
                this.triggerChangeEvent(editor);
            }
        );

        return placeholder;
    }