【问题标题】:odoo 13 upload video files via minio api of Pythonodoo 13 通过 Python 的 minio api 上传视频文件
【发布时间】:2020-08-13 03:32:31
【问题描述】:

我正在尝试开发一个模块来通过 Python 的 MinIO API 上传视频文件。

该文件可以上传到 MinIO,但无法通过以下网址查看:http://localhost:9000/lms-videos/video/output.mp4。而且通过MinIO上传的文件应该是19.39Mb,通过API上传的文件是25+MB,不知道是什么原因.....

以下是我的代码的一部分:

# minio client
@api.model
def _get_minio_client(self):
    host = '192.168.1.102:9000'
    access_key = 'minioadmin'
    secret_key = 'minioadmin'
    if not all((host, access_key, secret_key)):
        raise exceptions.UserError('Incorrect configuration of MinIO')
    return Minio(
    host,
    access_key = access_key,
    secret_key = secret_key,
    secure = False
    )
# upload
@api.model
def _store_file_write(self):
    client = self._get_minio_client()
    bin_data = self.datas_minio
    fname = "output_test"
    #client.put_object('lms-videos','videos/'+ fname + '.mp4',io.BytesIO(self.datas_minio), len(bin_data),'video/mp4')
    with io.BytesIO(self.datas_minio) as bin_data_io:
        client.put_object('lms-videos',
                          'videos/'+ fname + '.mp4',
                          bin_data_io,
                          len(bin_data),
                          'video/mp4')

@api.depends('document_id', 'slide_type', 'mime_type', 'external_url')
def _compute_embed_code(self):
    res = super(Slide, self)._compute_embed_code()
    for record in self:
        if record.slide_type == 'miniovideo':
            
            self._store_file_write()
            
            content_url = 'http://localhost:9000/lms-videos/videos/' + record.name + '.mp4'
            record.embed_code = '<video class="miniovideo" controls controlsList="nodownload"><source src="' + content_url + '" type=MPEG-4/></video>'
        
@api.onchange('datas_minio')
def _on_change_datas(self):
    res = super(Slide, self)._on_change_datas()
    if self.datas_minio:
        #fname = self.datas_minio.decode("utf-8")
        #bin_data = self.datas_minio
        self._store_file_write()
        #self._get_minio_client().put_object('lms-videos', '/videos/'+ fname + '.mp4',io.BytesIO(bin_data), len(bin_data),'video/mp4')
    return res

【问题讨论】:

    标签: python odoo minio bytesio


    【解决方案1】:

    通过添加 b64decode 解决的问题

    @api.model
        def _store_file_write(self):
            client = self._get_minio_client()
            bin_data = base64.b64decode(self.datas_minio)
            fsize = len(bin_data)
            fname = "output_test"
           
            with io.BytesIO(bin_data) as bin_data_io:
                client.put_object('lms-videos',
                                  #'videos/'+ fname + '.mp4',
                                  'videos/output_test.mp4',
                                  bin_data_io,
                                  fsize,
                                  'video/mp4')
    

    【讨论】:

      猜你喜欢
      • 2014-09-27
      • 2012-08-19
      • 1970-01-01
      • 1970-01-01
      • 2020-07-29
      • 2023-03-13
      • 1970-01-01
      • 2020-12-17
      • 1970-01-01
      相关资源
      最近更新 更多