|
1 | 1 | {% extends "base.html" %} |
2 | 2 | {% block content %} |
3 | 3 | <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='css/chat.css') }}"> |
| 4 | +<meta name="csrf-token" content="{{ csrf_token() }}"> |
4 | 5 | <div class="container" style="margin-top: 10px"> |
5 | 6 | <div id="chat-room-widget" style="margin-top: 10px"> |
6 | 7 | <div id="messages"> |
7 | 8 | </div> |
8 | 9 | <form id="chatForm" name="chatForm" action="{{url_for('chat.invoke')}}" method="post" enctype="multipart/form-data"> |
| 10 | + <input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/> |
9 | 11 | <div id="message-box"> |
10 | 12 | <div class="col-md-8"> |
11 | 13 | <textarea id="prompt" name="message" placeholder="How can I help?" class="form-control" rows="1" required onkeyup="stoppedTyping()"></textarea> |
|
39 | 41 | // Select your input type file and store it in a variable |
40 | 42 | document.querySelector("#chatForm").addEventListener("submit", async (e) => { |
41 | 43 | e.preventDefault(); |
| 44 | + var csrf_token = $('meta[name=csrf-token]').attr('content'); |
42 | 45 | const prompt = document.querySelector("#prompt").value; |
43 | 46 | const image = document.querySelector("#image"); |
44 | 47 | const receipt = document.querySelector("#checkReceipt").checked; |
|
48 | 51 | form.append("prompt", prompt); |
49 | 52 | form.append("receipt", receipt); |
50 | 53 | if (image && image.files.length && image.files[0]) { |
51 | | - console.log(`Image name: ${image.files[0].name}, size: ${image.files[0].size}, type: ${image.files[0].type}`); |
| 54 | + //console.log(`Image name: ${image.files[0].name}, size: ${image.files[0].size}, type: ${image.files[0].type}`); |
52 | 55 | form.append("image", image.files[0]); |
53 | 56 | }// else |
54 | 57 | //console.log("No file selected!"); |
|
77 | 80 | const response = await fetch('invoke', { /* Without forward-slash prefix! */ |
78 | 81 | method: 'POST', |
79 | 82 | //headers: { 'Content-Type': 'multipart/form-data' }, Do NOT declare Content-Type: multipart/form-data in request header |
| 83 | + headers: { |
| 84 | + "X-CSRFToken": csrf_token, |
| 85 | + }, |
80 | 86 | body: form |
81 | 87 | }); |
82 | 88 | const data = await response.json(); |
|
0 commit comments