当前位置: 首页> 游戏> 手游 > 国家企业信用信息公示系统平台_餐厅装修_长沙谷歌优化_适合员工的培训课程

国家企业信用信息公示系统平台_餐厅装修_长沙谷歌优化_适合员工的培训课程

时间:2025/7/23 15:52:10来源:https://blog.csdn.net/weixin_73495056/article/details/146437531 浏览次数:1次
国家企业信用信息公示系统平台_餐厅装修_长沙谷歌优化_适合员工的培训课程

功能实现

  1. RabbitMq接收hello里面传来的消息
  2. 根据消息在 MobileFile里面新建文件
  3. 新建文件上传到minio

python 新建文件

import  os  path = './MobileFile'  file_path = os.path.join(path,"new_file.txt")  with open(file_path, "w") as file:  pass

转换成函数格式

import  os  
def createfile(filename):  path = '.\\MobileFile'  file_path = os.path.join(path,f"{filename}")  print(file_path)  with open(file_path, "w") as file:  pass

minio上传文件函数

def upfile(body):  # 上传的文件 source_file = f"./MobileFile/{body}"  # The destination bucket and filename on the MinIO server  bucket_name = "python-test-bucket"  destination_file = f"{body}"  # 如果桶不存在就新建found = client.bucket_exists(bucket_name)  if not found:  client.make_bucket(bucket_name)  # 上传文件client.fput_object(  bucket_name, destination_file, source_file,  )  print(  source_file, "successfully uploaded as object",  destination_file, "to bucket", bucket_name,  )

rabbitMq消息问题

rabbitMq传送过来的消息是字节,我们要进行一个字节的转换

字节转换函数

def typechangetoNomal(body):  strbody = str(body)return body[2:len(body)-1]

原理,打印出来的是 b’body’
我们只需要打印出body即可,也就是说,转换成字符串之后选取第三个到最后第二个就行。

callBack函数(即收到消息执行的函数)

def callback(ch, method, properties, body):  body = typechangetoNomal(body)  # print(newbody)  #新建文件夹 已完成  myFileController.createfile(body)  #上传到minio里面  myMinio.upfile(body)

问题发现

python文件名如果带数字就import出现问题

关键字:国家企业信用信息公示系统平台_餐厅装修_长沙谷歌优化_适合员工的培训课程

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: