file_manager.py 595 B

1234567891011121314151617181920212223242526
  1. import hashlib
  2. import requests
  3. def download_file(file_url, local_file_path):
  4. reply = requests.get(file_url)
  5. with open(local_file_path, 'wb') as f:
  6. f.write(reply.content)
  7. def upload_file(file_name):
  8. data = {'file_path': file_name}
  9. reply = requests.post('https://127.0.0.1:5555/upload_file', data=data, files=data)
  10. return reply.json()
  11. def get_file_md5(file_path):
  12. md5 = hashlib.md5()
  13. with open(file_path, 'rb') as f:
  14. # 分块读取以支持大文件
  15. while chunk := f.read(8192):
  16. md5.update(chunk)
  17. return md5.hexdigest()