I want to transfer a file, such a form

<form enctype="multipart/form-data"><input type="file" id="logo" @change="LogoUpload($event.target.files)"></form> 

The method is not intricate

 let form = new FormData(); form.append("file",files[0]); fetch("http://127.0.0.1",{method:'post',headers:{"Content-type":"multipart/form-data"}, body : form}); 

the problem is that the content is not transmitted

 ------WebKitFormBoundary9wcnRDYkOAFMdLOo Content-Disposition: form-data; name="file"; filename="a9J63zXOn8s.jpg" Content-Type: image/jpeg ------WebKitFormBoundary9wcnRDYkOAFMdLOo-- 

I tried it through axios too, ruzeltat is the same.

  • but tried not to set the Content-type , through XMLHttpRequest I do not set this header - Alexander Lonberg
  • By the way, here is developer.mozilla.org/ru/docs/Web/API/Fetch_API/Using_Fetch example, where fetch + FormData also without Content-type - Alexander Lonberg
  • Yes, I tried it without the Content-type, the result is the same, mysticism is straightforward - Vladimir Aristarkhov

0