【发布时间】:2021-01-10 19:12:54
【问题描述】:
不知道如何通过请求将图像作为 base64 字符串发送以将其存储为 sqlite FastAPI 框架中的 blob 对象,并且不知道使用哪种方法,使用 formdata 或 ??? 有什么方法可以完成上述任务
var pimagefile = document.getElementById("pImage").files[0];
var pimageblob = new Blob([pimagefile],{type: 'image/jpg'});
function convertToBase64(){
var pimageBase64 = // convert to base64 string
}
var toSend = {
pimage: pimageBase64
}
var jsonString = JSON.stringify(toSend);
var xhttp = new XMLHttpRequest();
xhttp.open("POST", "http://127.0.0.1:8000/products/add/", true);
xhttp.setRequestHeader("Content-Type", "application/json");
xhttp.send(jsonString);
【问题讨论】:
标签: javascript python image xmlhttprequest fastapi