mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-08-28 19:47:41 +08:00
Merge pull request #4946 from developer-wlj/wlj0914
This commit is contained in:
+8
-6
@@ -458,16 +458,17 @@ class MediaChain(ChainBase):
|
|||||||
if not _fileitem or not _content or not _path:
|
if not _fileitem or not _content or not _path:
|
||||||
return
|
return
|
||||||
# 使用tempfile创建临时文件,手动删除
|
# 使用tempfile创建临时文件,手动删除
|
||||||
with NamedTemporaryFile(delete=False, suffix=_path.suffix) as tmp_file:
|
tmp_file = NamedTemporaryFile(delete=False, suffix=_path.suffix)
|
||||||
tmp_file_path = Path(tmp_file.name)
|
tmp_file_path = Path(tmp_file.name)
|
||||||
|
try:
|
||||||
# 写入内容
|
# 写入内容
|
||||||
if isinstance(_content, bytes):
|
if isinstance(_content, bytes):
|
||||||
tmp_file.write(_content)
|
tmp_file.write(_content)
|
||||||
else:
|
else:
|
||||||
tmp_file.write(_content.encode('utf-8'))
|
tmp_file.write(_content.encode('utf-8'))
|
||||||
tmp_file.flush()
|
tmp_file.flush()
|
||||||
|
tmp_file.close() # 关闭文件句柄
|
||||||
|
|
||||||
try:
|
|
||||||
# 上传文件
|
# 上传文件
|
||||||
item = storagechain.upload_file(fileitem=_fileitem, path=tmp_file_path, new_name=_path.name)
|
item = storagechain.upload_file(fileitem=_fileitem, path=tmp_file_path, new_name=_path.name)
|
||||||
if item:
|
if item:
|
||||||
@@ -496,15 +497,16 @@ class MediaChain(ChainBase):
|
|||||||
with request_utils.get_stream(url=_url) as r:
|
with request_utils.get_stream(url=_url) as r:
|
||||||
if r and r.status_code == 200:
|
if r and r.status_code == 200:
|
||||||
# 使用tempfile创建临时文件,手动删除
|
# 使用tempfile创建临时文件,手动删除
|
||||||
with NamedTemporaryFile(delete=False, suffix=_path.suffix) as tmp_file:
|
tmp_file = NamedTemporaryFile(delete=False, suffix=_path.suffix)
|
||||||
tmp_file_path = Path(tmp_file.name)
|
tmp_file_path = Path(tmp_file.name)
|
||||||
|
try:
|
||||||
# 流式写入文件
|
# 流式写入文件
|
||||||
for chunk in r.iter_content(chunk_size=8192):
|
for chunk in r.iter_content(chunk_size=8192):
|
||||||
if chunk:
|
if chunk:
|
||||||
tmp_file.write(chunk)
|
tmp_file.write(chunk)
|
||||||
tmp_file.flush()
|
tmp_file.flush()
|
||||||
|
tmp_file.close() # 关闭文件句柄
|
||||||
|
|
||||||
try:
|
|
||||||
# 上传文件
|
# 上传文件
|
||||||
item = storagechain.upload_file(fileitem=_fileitem, path=tmp_file_path,
|
item = storagechain.upload_file(fileitem=_fileitem, path=tmp_file_path,
|
||||||
new_name=_path.name)
|
new_name=_path.name)
|
||||||
|
|||||||
Reference in New Issue
Block a user