In this blog, we will explore how to upload an image from a custom form and save it to a Dataverse table's Image column using the Web API.

GOAL

Screenshot - 2026-02-10T145203.920Screenshot - 2026-02-10T145304.102

Stepwise Implementation

1 - Configure site settings (Web API) & Table permissions for Table

2 - Assign web roles to Demo Table.

3 - UI Design of Form which i have used in Demo with file input

Screenshot - 2026-02-10T145655.611

4 - JS Code Example : Submit button code

const submitBtn = document.getElementById("submit-btn")
submitBtn.addEventListener("click", saveRecord)

function saveRecord() {
    // console.log("Hello")
    const nameValue = name.value
    const priceValue = parseFloat(price.value)
    const file = fileInput.files[0]

    const record = {
        cr399_name: nameValue,
        cr399_price: priceValue
    }

    webapi.safeAjax({
        type: "POST",
        url: "/_api/cr399_stockdatas",
        contentType: "application/json",
        data: JSON.stringify(record),
        success: function (res, status, xhr) {
            productId = xhr.getResponseHeader("EntityId")
            console.log("Product Id: ", productId)
            if (file) {
                uploadImage(productId, file)
            } else {
                alert("Data saved without file")
            }
        }, error: function (xhr, status, error) {
            console.error("Failed to save record", error);

        }
    })
}

function uploadImage(id, file){
    const reader = new FileReader();
    reader.addEventListener("load", (e) => {
        const base64String = e.target.result.split(",")[1];

        const record = {
            cr399_image: base64String
        }

        webapi.safeAjax({
            type: "PATCH", 
            url: `/_api/cr399_stockdatas(${id})`, 
            contentType: "application/json", 
            data: JSON.stringify(record), 
            success: function(){
                alert("Image uploaded")
            }, error: function(err){
                console.error("Image upload failed", err);
                
            }
        })
    })
    reader.readAsDataURL(file)
}

1 - Save Record Function

# Record Creation:

2 - Upload Image Function

# Sending Image to Dataverse:

Conclusion

In this article, we’ve learned how to upload an image from a custom form and save it to a Dataverse table’s Image column using the Web API. We used the FileReader to convert the image into a base64 string, and then we sent the data to Dataverse using a PATCH request.