Advertisement
Guest User

bora

a guest
Oct 18th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7. <title>sobe-img</title>
  8. </head>
  9. <body>
  10. <input type="file" id="imagem" multiple="multiple">
  11. <button id="btn-submit">Submit</button>
  12. <script>
  13. // Select your input type file and store it in a variable
  14. const inputFile = document.getElementById('imagem');
  15. const inputSubmit = document.getElementById('btn-submit');
  16.  
  17.  
  18. // let formData = new FormData();
  19.  
  20. // let options = {
  21. // method: 'POST',
  22. // body: formData
  23.  
  24.  
  25. inputSubmit.addEventListener("click", (event) => {
  26. let formData = new FormData();
  27.  
  28. let options = {
  29. method: 'POST',
  30. body: formData
  31. }
  32.  
  33. formData.append('file', inputFile.files[0]);
  34. fetch('http://localhost:8000/upload_img', options)
  35. .then((response) => {
  36. return response.json();
  37. })
  38. .then((json) => {
  39.  
  40. let input = `{"title": "kamzu","paths": "${json.output}"}`;
  41. let options = {
  42. method:'POST',
  43. headers: { "Content-Type" : "application/json" },
  44. body: input
  45. }
  46. fetch('http://localhost:8000/add_event', options)
  47. })
  48.  
  49. })
  50.  
  51. </script>
  52. </body>
  53. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement