Fetch sends pictures to the background

is canvas a picture that has been encoded by base64? how can it be sent to the background or json?

        fetch("/api/avatarUp",{
            method:"POST",
            headers: {
                "Accept": "application/json",
                "Content-Type":"application/json;charset=UTF-8"
            },
            body:JSON.stringify({avatar:canvas}),
        }).then(res => res.blob())
           .then(blob => (
               img = window.URL.createObjectURL(blob),
               this.setState({img})
               )).catch(e => console.log(e))

Mar.02,2021

use the fetch method to transfer the json data to the background, and the picture is also possible.
you can refer to this article: https://blog.csdn.net/withing.


just pass the picture of base64 to the background as a parameter.

Menu