upload.html 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <html>
  2. <head></head>
  3. <body>
  4. Куда лить: <br /><input type="file" id="file" />
  5. <a href="#" id="url">url</a>
  6. <script>
  7. file.onchange = async () => {
  8. url.innerHTML = url.href =
  9. "/" +
  10. (await (
  11. await fetch("http://shop-roles.asmer.fs.a-level.com.ua/upload", {
  12. method: "POST",
  13. headers: localStorage.authToken
  14. ? { Authorization: "Bearer " + localStorage.authToken }
  15. : {},
  16. body: file.files[0],
  17. })
  18. ).text());
  19. };
  20. </script>
  21. <form action="/upload" method="post" enctype="multipart/form-data" id="form">
  22. <input type="file" name="photo" id="photo" />
  23. </form>
  24. <script>
  25. photo.onchange = async () => {
  26. fetch("http://shop-roles.asmer.fs.a-level.com.ua/upload", {
  27. method: "POST",
  28. headers: localStorage.authToken
  29. ? { Authorization: "Bearer " + localStorage.authToken }
  30. : {},
  31. body: new FormData(form),
  32. })
  33. .then((res) => res.json())
  34. .then((res) => console.log("UPLOAD RESULT", res));
  35. };
  36. </script>
  37. </body>
  38. </html>