Image upload process. The front end asks for an explanation
Image upload process. The front end asks for an explanation
1. inputonchange
2. formdata
3. POST
document.querySelector('-sharpfile').onchange = function(e) {
if(e.files.length === 0) {
return;
}
const fd = new FormData();
fd.append('file',e.files[0]);
fetch('http://www.baidu.com/upload').then(res=>console.log(res)).catch(console.error);
}
use formdata, View documents
want to hear how to explain.
there are many picture upload schemes
my front end usually converts the picture into a base64 string, and when requesting the backend data interface, the base64 string is passed to the backend