윤영준 윤영준 05-20
still working on sending file as is
@d6599d5fb52bdfae4230bfff05bc1ca4b2463c9e
hls_streaming/hls.py
--- hls_streaming/hls.py
+++ hls_streaming/hls.py
@@ -3,6 +3,7 @@
 import cv2
 import numpy as np
 import requests
+from requests_toolbelt.multipart.encoder import MultipartEncoder
 from zoneinfo import ZoneInfo
 from datetime import datetime
 from threading import Lock, Thread, Event
@@ -87,14 +88,20 @@
             'x-cctv-latitude' : '',
             'x-cctv-longitude' : '',
         }
+        session = requests.Session()
         try:
-            file = {
-                'image': (f'frame_{self.cctvid}.{image_type}',
-                              image,
-                              f'image/{image_type}')
-                    }
-            requests.post(endpoint, headers=header, files=file)
-        except:
+            multipart_data = MultipartEncoder(
+                fields = {
+                    'file': (f'frame_{self.cctvid}.{image_type}',
+                                  image,
+                                  f'image/{image_type}')
+                        }
+            )
+            header["Content-Type"] = multipart_data.content_type
+            response = session.post(endpoint, headers=header, data=multipart_data)
+
+        except Exception as e:
+            print(e)
             print("Can not connect to the analyzer server. Check the endpoint address or connection.\n"
                   f"Can not connect to : {self.endpoint}")
 
@@ -114,7 +121,7 @@
 # Example usage
 if __name__ == "__main__":
     capturer = FrameCapturer(
-        'http://cctvsec.ktict.co.kr/71187/bWDrL7fpStZDeDZgCybpJH8gagWJOynbaA/l91ExpmUPKzc3bCsHJtIblDkzG3Tff2tHy5NNkb6NtYTbie/jNQ0F+PnejViTbKHkpMWNGpc=',
+        'http://cctvsec.ktict.co.kr/5545/LFkDslDT81tcSYh3G4306+mcGlLb3yShF9rx2vcPfltwUL4+I950kcBlD15uWm6K0cKCtAMlxsIptMkCDo5lGQiLlARP+SyUloz8vIMNB18=',
         101, 10
     )
     t1 = time.time()
test.py
--- test.py
+++ test.py
@@ -26,14 +26,13 @@
 
 @ns.route('/infer', )
 class ImageUpload(Resource):
-    @ns.expect(image_upload_model, validate=True)
+    # @ns.expect(image_upload_model, validate=True)
     @ns.response(200, 'Success')
     @ns.response(400, 'Validation Error')
     def post(self):
-        if 'image' not in request.files:
+        if 'file' not in request.files:
             ns.abort(400, 'No image part in the request')
-
-        image = request.files['image']
+        image = request.files['file']
         cctv_info = request.headers.get('x-cctv-info', '')
         time_sent = request.headers.get('x-time-sent', '')
         cctv_latitude = request.headers.get('x-cctv-latitude', 'Not provided')
Add a comment
List