index.html 799 B

12345678910111213141516171819202122232425
  1. Куда лить: <br/><input type='file' id='file' />
  2. <a href='#' id='url'></a>
  3. <script>
  4. file.onchange = async () => {
  5. url.innerHTML = url.href = "/" + await (await fetch('/upload', {
  6. method: "POST",
  7. headers: localStorage.authToken ? {Authorization: 'Bearer ' + localStorage.authToken} : {},
  8. body: file.files[0]
  9. })).text()
  10. }
  11. </script>
  12. <form action="/upload" method="post" enctype="multipart/form-data" id='form'>
  13. <input type="file" name="photo" id='photo'/>
  14. </form>
  15. <script>
  16. photo.onchange = async () => {
  17. fetch('/upload', {
  18. method: "POST",
  19. headers: localStorage.authToken ? {Authorization: 'Bearer ' + localStorage.authToken} : {},
  20. body: new FormData(form)
  21. })
  22. }
  23. </script>