Skip to content

Commit e5f46cb

Browse files
committed
Update python input file
1 parent c3f7957 commit e5f46cb

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

src/SDK/Language/Python.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ public function getParamExample(array $param)
302302
$output .= '{}';
303303
break;
304304
case self::TYPE_FILE:
305-
$output .= "'file.png'";
305+
$output .= "InputFile.from_path('file.png')";
306306
break;
307307
}
308308
}
@@ -321,7 +321,7 @@ public function getParamExample(array $param)
321321
$output .= "'{$example}'";
322322
break;
323323
case self::TYPE_FILE:
324-
$output .= "'file.png'";
324+
$output .= "InputFile.from_path('file.png')";
325325
break;
326326
}
327327
}
Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
1+
import os
2+
import mimetypes
3+
14
class InputFile:
2-
def __init__(self, path, name, file):
3-
self.path = path
4-
self.name = name
5-
self.file = file
5+
@classmethod
6+
def from_path(cls, path):
7+
instance = cls()
8+
instance.path = path
9+
instance.filename = os.path.basename(path)
10+
instance.mime_type = mimetypes.guess_type(path)
11+
instance.source_type = 'path'
12+
return instance
13+
14+
@classmethod
15+
def from_bytes(cls, bytes, filename = None, mime_type = None):
16+
instance = cls()
17+
instance.data = bytes
18+
instance.filename = filename
19+
instance.mime_type = mime_type
20+
instance.source_type = 'bytes'
21+
return instance

0 commit comments

Comments
 (0)