Skip to content

Commit d9f2d0f

Browse files
zakahanyaozheng-fang
authored andcommitted
feat: add message support network source (#54)
1 parent 7922de2 commit d9f2d0f

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

veadk/utils/misc.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414

1515
import time
16+
import requests
1617

1718

1819
def read_file(file_path):
@@ -28,6 +29,14 @@ def formatted_timestamp():
2829

2930

3031
def read_png_to_bytes(png_path: str) -> bytes:
31-
with open(png_path, "rb") as f:
32-
data = f.read()
32+
# Determine whether it is a local file or a network file
33+
if png_path.startswith(("http://", "https://")):
34+
# Network file: Download via URL and return bytes
35+
response = requests.get(png_path)
36+
response.raise_for_status() # Check if the HTTP request is successful
37+
return response.content
38+
else:
39+
# Local file
40+
with open(png_path, "rb") as f:
41+
data = f.read()
3342
return data

0 commit comments

Comments
 (0)