12345678910111213141516171819202122232425262728293031323334353637383940 |
- <html>
- <head></head>
- <body>
- Куда лить: <br /><input type="file" id="file" />
- <a href="#" id="url">url</a>
- <script>
- file.onchange = async () => {
- url.innerHTML = url.href =
- "/" +
- (await (
- await fetch("http://shop-roles.asmer.fs.a-level.com.ua/upload", {
- method: "POST",
- headers: localStorage.authToken
- ? { Authorization: "Bearer " + localStorage.authToken }
- : {},
- body: file.files[0],
- })
- ).text());
- };
- </script>
- <form action="/upload" method="post" enctype="multipart/form-data" id="form">
- <input type="file" name="photo" id="photo" />
- </form>
- <script>
- photo.onchange = async () => {
- fetch("http://shop-roles.asmer.fs.a-level.com.ua/upload", {
- method: "POST",
- headers: localStorage.authToken
- ? { Authorization: "Bearer " + localStorage.authToken }
- : {},
- body: new FormData(form),
- })
- .then((res) => res.json())
- .then((res) => console.log("UPLOAD RESULT", res));
- };
- </script>
- </body>
- </html>
|