--- hls_streaming/hls.py
+++ hls_streaming/hls.py
... | ... | @@ -3,6 +3,7 @@ |
3 | 3 |
import cv2 |
4 | 4 |
import numpy as np |
5 | 5 |
import requests |
6 |
+from requests_toolbelt.multipart.encoder import MultipartEncoder |
|
6 | 7 |
from zoneinfo import ZoneInfo |
7 | 8 |
from datetime import datetime |
8 | 9 |
from threading import Lock, Thread, Event |
... | ... | @@ -87,14 +88,20 @@ |
87 | 88 |
'x-cctv-latitude' : '', |
88 | 89 |
'x-cctv-longitude' : '', |
89 | 90 |
} |
91 |
+ session = requests.Session() |
|
90 | 92 |
try: |
91 |
- file = { |
|
92 |
- 'image': (f'frame_{self.cctvid}.{image_type}', |
|
93 |
- image, |
|
94 |
- f'image/{image_type}') |
|
95 |
- } |
|
96 |
- requests.post(endpoint, headers=header, files=file) |
|
97 |
- except: |
|
93 |
+ multipart_data = MultipartEncoder( |
|
94 |
+ fields = { |
|
95 |
+ 'file': (f'frame_{self.cctvid}.{image_type}', |
|
96 |
+ image, |
|
97 |
+ f'image/{image_type}') |
|
98 |
+ } |
|
99 |
+ ) |
|
100 |
+ header["Content-Type"] = multipart_data.content_type |
|
101 |
+ response = session.post(endpoint, headers=header, data=multipart_data) |
|
102 |
+ |
|
103 |
+ except Exception as e: |
|
104 |
+ print(e) |
|
98 | 105 |
print("Can not connect to the analyzer server. Check the endpoint address or connection.\n" |
99 | 106 |
f"Can not connect to : {self.endpoint}") |
100 | 107 |
|
... | ... | @@ -114,7 +121,7 @@ |
114 | 121 |
# Example usage |
115 | 122 |
if __name__ == "__main__": |
116 | 123 |
capturer = FrameCapturer( |
117 |
- 'http://cctvsec.ktict.co.kr/71187/bWDrL7fpStZDeDZgCybpJH8gagWJOynbaA/l91ExpmUPKzc3bCsHJtIblDkzG3Tff2tHy5NNkb6NtYTbie/jNQ0F+PnejViTbKHkpMWNGpc=', |
|
124 |
+ 'http://cctvsec.ktict.co.kr/5545/LFkDslDT81tcSYh3G4306+mcGlLb3yShF9rx2vcPfltwUL4+I950kcBlD15uWm6K0cKCtAMlxsIptMkCDo5lGQiLlARP+SyUloz8vIMNB18=', |
|
118 | 125 |
101, 10 |
119 | 126 |
) |
120 | 127 |
t1 = time.time() |
--- test.py
+++ test.py
... | ... | @@ -26,14 +26,13 @@ |
26 | 26 |
|
27 | 27 |
@ns.route('/infer', ) |
28 | 28 |
class ImageUpload(Resource): |
29 |
- @ns.expect(image_upload_model, validate=True) |
|
29 |
+ # @ns.expect(image_upload_model, validate=True) |
|
30 | 30 |
@ns.response(200, 'Success') |
31 | 31 |
@ns.response(400, 'Validation Error') |
32 | 32 |
def post(self): |
33 |
- if 'image' not in request.files: |
|
33 |
+ if 'file' not in request.files: |
|
34 | 34 |
ns.abort(400, 'No image part in the request') |
35 |
- |
|
36 |
- image = request.files['image'] |
|
35 |
+ image = request.files['file'] |
|
37 | 36 |
cctv_info = request.headers.get('x-cctv-info', '') |
38 | 37 |
time_sent = request.headers.get('x-time-sent', '') |
39 | 38 |
cctv_latitude = request.headers.get('x-cctv-latitude', 'Not provided') |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?