MCPcopy
hub / github.com/1Panel-dev/MaxKB / bytes_to_uploaded_file

Function bytes_to_uploaded_file

apps/common/utils/common.py:205–225  ·  view source on GitHub ↗
(file_bytes, file_name="file.txt")

Source from the content-addressed store, hash-verified

203
204
205def bytes_to_uploaded_file(file_bytes, file_name="file.txt"):
206 content_type, _ = mimetypes.guess_type(file_name)
207 if content_type is None:
208 # 如果未能识别,设置为默认的二进制文件类型
209 content_type = "application/octet-stream"
210 # 创建一个内存中的字节流对象
211 file_stream = io.BytesIO(file_bytes)
212
213 # 获取文件大小
214 file_size = len(file_bytes)
215
216 # 创建 InMemoryUploadedFile 对象
217 uploaded_file = InMemoryUploadedFile(
218 file=file_stream,
219 field_name=None,
220 name=file_name,
221 content_type=content_type,
222 size=file_size,
223 charset=None,
224 )
225 return uploaded_file
226
227
228def any_to_amr(any_path, amr_path):

Callers 8

editMethod · 0.90
insertMethod · 0.90
save_workflowMethod · 0.90
editMethod · 0.90
executeMethod · 0.90
executeMethod · 0.90
executeMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected