For the picture 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

  1. oss Direct transfer Pure Front end Operation
  2. file object transfer background to do the rest of the upload processing
  3. Picture to base64 is being processed

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

Menu